Possible Duplicate:
getting current URL
PHP and invoking url?
Say somebody is looking for
http://subdomain.domainname.com/somedirectory/somefile.htm
What $_SERVER variable contain http://subdomain.domainname.com/somedirectory/somefile.htm
Possible Duplicate:
getting current URL
PHP and invoking url?
Say somebody is looking for
http://subdomain.domainname.com/somedirectory/somefile.htm
What $_SERVER variable contain http://subdomain.domainname.com/somedirectory/somefile.htm
// Get HTTP/HTTPS (the possible values for this vary from server to server)
$myUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && !in_array(strtolower($_SERVER['HTTPS']),array('off','no'))) ? 'https' : 'http';
// Get domain portion
$myUrl .= '://'.$_SERVER['HTTP_HOST'];
// Get path to script
$myUrl .= $_SERVER['REQUEST_URI'];
// Add path info, if any
if (!empty($_SERVER['PATH_INFO'])) $myUrl .= $_SERVER['PATH_INFO'];
// Add query string, if any (some servers include a ?, some don't)
if (!empty($_SERVER['QUERY_STRING'])) $myUrl .= '?'.ltrim($_SERVER['REQUEST_URI'],'?');
echo $myUrl;
...is my most resilient routine for this.
You might like to try:
echo '<pre>';
print_r($_SERVER);
echo '</pre>';
A combination of $_SERVER['HTTP_HOST']
and $_SERVER['SCRIPT_NAME']
or $_SERVER['PHP_SELF']
should be what you are looking for.
You need to build it yourself;
echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
You can also use $_SERVER['HTTPS']
to detect if HTTP or HTTPS.
I recommend using $_SERVER['REQUEST_URI']
as this is exactly what the user is looking for, before any rewrites or anything else, and includes GET variables
There is no full url contain in $_SERVER. But you can use this code:
$url = "http://" . $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF'] . "/" . $_SERVER['QUERYSTRING'] . "/";