How to find the full URL of the page in PHP in a platform independent and configuration independent way
By Angsuman Chakraborty, Gaea News NetworkFriday, June 3, 2005
Without much ado, I present the script.
It handles http and https URL’s and should work across platforms and configurations (like using htaccess for clean url’s etc.).
To understand more about the issues involved read - Understanding $_SERVER[’PHP_SELF’], $PHP_SELF, $_SERVER[’REQUEST_URI’] and $_SERVER[’SCRIPT_NAME’] in PHP and when to use what
$_SERVER['FULL_URL'] = 'http';
$script_name = '';
if(isset($_SERVER['REQUEST_URI'])) {
$script_name = $_SERVER['REQUEST_URI'];
} else {
$script_name = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']>' ') {
$script_name .= '?'.$_SERVER['QUERY_STRING'];
}
}
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') {
$_SERVER['FULL_URL'] .= 's';
}
$_SERVER['FULL_URL'] .= '://';
if($_SERVER['SERVER_PORT']!='80') {
$_SERVER['FULL_URL'] .=
$_SERVER['HTTP_HOST'].':'.$_SERVER['SERVER_PORT'].$script_name;
} else {
$_SERVER['FULL_URL'] .= $_SERVER['HTTP_HOST'].$script_name;
}
April 6, 2010: 12:21 am
You can find full url from this coding —-> |
Md Irshad |
Md Irshad |
April 5, 2010: 7:42 am
You can find the full url from the javascript and after that you can convert in PHP. Script is var aa = document.location.href; |
May 8, 2009: 10:37 am
hii thanks for the above info, what i need to trace is not ust url with query strin but i also need to trace #href i.e. if my url is then till |
August 22, 2008: 12:22 pm
This script will NOT take in to account any redirects. They will show up in $_SERVER['REDIRECT_URL'] and $_SERVER['REDIRECT_QUERY_STRING'] but they are not bullet proof. It depends on how the redirect is made. |
oscar |
Nils |
June 6, 2005: 8:58 am
The uploaded code-snipped was broken: $port = ”; |
Nils |
June 6, 2005: 8:56 am
The generated url will work, but the port for https is 443. And the IIS may not set $_SERVER['HTTP_HOST']: ‘ ‘) { |
Md. Irshad