Entry
How can I get the URL of the current page that the script is processing?
How can I get the *FULL* URL of the current script, including the URL fraction (.../foo.php#bar)?
May 29th, 2002 08:57
Philip Olson, Nathan Wallace, Oskar Austegard,
There are many predefined variables that contain a lot of information,
a good way to figure out exactly what you need/want is to make a call
to phpinfo() in your script (foo.php below):
http://www.example.com/dir/foo.php?fruit=apple&color=red
A few predefined variables that you'll see:
PHP_SELF : /dir/foo.php
QUERY_STRING : fruit=apple&color=red
REQUEST_URI : /dir/foo.php?fruit=apple&color=red
To access these predefined variables, try either:
// Works since PHP 3
print $HTTP_SERVER_VARS['PHP_SELF'];
// Works since PHP 4.1.0
print $_SERVER['PHP_SELF'];
// Works if the PHP directive register_globals = on.
// Note: The default for this directive is off since
// PHP 4.2.0
print $PHP_SELF;
More can be read about reserved and predefined variables here:
http://www.php.net/manual/en/language.variables.predefined.php
The information after the # in an URL is not available to the server
hence it won't be available to PHP, only client-side.