I know that this is likely easy, but I need to know so that I can figure out where the user is in my developers code. I need to read which directory they are in, and what page they are opening. ex (home.html/directory2/page%2055.html .
input is very appreciated.
thank you.
mike
Getting URL Address in PHP variable
Moderator: General Moderators
-
mparker1113
- Forum Commoner
- Posts: 28
- Joined: Wed Apr 05, 2006 9:39 am
- mattcooper
- Forum Contributor
- Posts: 210
- Joined: Thu Mar 17, 2005 5:51 am
- Location: London, UK
One way to do this is to use:
This should return the information you require in the form of a full URL string. If you want to break it down to just top directory and filename, use explode() with "/" as the separator and reverse the array of the exploded parts with array_reverse(); then, use the first two elements of the array to create the info you need.
For http://www.mydomain.com/path/to/file.php, something like:
Will give you "to/file.php".
To output:
That's off the top of my head and untested, but is the way I would try to do it... let me know how you go!
Code: Select all
$_SERVER[PHP_SELF];For http://www.mydomain.com/path/to/file.php, something like:
Code: Select all
$location = $_SERVER[PHP_SELF];
$split = explode("/","$location");
$array = array_reverse($split);
$filename = $array[0];
$directory = $array[1];To output:
Code: Select all
;
echo $directory."/".$filename;- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
-
mparker1113
- Forum Commoner
- Posts: 28
- Joined: Wed Apr 05, 2006 9:39 am