Page 1 of 1
Getting URL Address in PHP variable
Posted: Wed Jun 28, 2006 4:29 pm
by mparker1113
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
Posted: Wed Jun 28, 2006 6:30 pm
by mattcooper
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:
Code: Select all
$location = $_SERVER[PHP_SELF];
$split = explode("/","$location");
$array = array_reverse($split);
$filename = $array[0];
$directory = $array[1];
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!
Posted: Wed Jun 28, 2006 6:42 pm
by Christopher
$_SERVER['SCRIPT_NAME'];
Posted: Wed Jun 28, 2006 6:46 pm
by mparker1113
Thank you, Men.
Some of this i had figured out, but you gave me better info to work with.
Thanks!
Posted: Wed Jun 28, 2006 6:49 pm
by Burrito