Forum Moderators: coopster

Message Too Old, No Replies

request url and extract portion to evaluate and get information

         

unbeatabletechnology

5:00 pm on Feb 11, 2007 (gmt 0)

10+ Year Member



I'm looking to take a url say testsite.com/test/1234. How can I detect what page I'm on using php with an if statement? After the page of this type is detected I would need the 1234 to lookup other information in a db and present to the user.

Currently for other pages say testsite.com/main.php?section=fun

require_once('dbconnect.php');

$section = $_REQUEST['section'];

$title_fun = "Your having fun!";

if ($section == "fun){
echo $title_fun;
}

scriptmasterdel

5:46 pm on Feb 11, 2007 (gmt 0)

10+ Year Member



If you would only like the last part of the path name then you can use the function basename with the servers current uri.

basename($_SERVER['REQUEST_URI']);

This will return the current filename / folder.

I use this with some of my standard CMS's

I hope i have helped.

Del

phparion

6:32 pm on Feb 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



read the URL by $_SERVER[REQUEST_URI] and then explode it by / i.e

$arr = explode("//",$URL);

i used extra slash to escape the slash bcz it has special meanings in php. then your $arr array's last element is what you are talking about.