PHP tutorials Comprehensive access to URL address bar parameters in a variety of ways
<?php
//Get domain name or host address
echo $_server[' Http_host '. <br> ";
//Get web address
echo $_server[' php_self '. <br> ";
//Get URL parameters
echo $_server["Query_string"]. <br> ";
//source page details address
echo $_server[' Http_referer '. <br> ";
?>
Method two uses? Number expression,
echo ' http://'. $_server[' server_name '. $_server["Server_port"].$_server["Request_uri"];
Method three is the same
function getServerName ()
{
$ServerName = strtolower ($_server[' server_name ']?$_server[' server_name ']:$_server[' http_host '));
if (Strpos ($ServerName, ' http://')
{
return str_replace (' http://', ', $ServerName);
}
return $ServerName;
}
//Instance invocation method
echo getServerName ();
Method Four, this relatively comprehensive get URL parameters, first with Request_uri if the server does not support the php_self do not support
query_string
function Getcururl ()
{
if (!empty ($_server["Request_uri"))
{
$scrtName = $_server["Request_uri"];
$nowurl = $scrtName;
}
Else
{
$scrtName = $_server["Php_self"];
if (Empty ($_server["query_string"))
{
$nowurl = $scrtName;
}
Else
{
$nowurl = $scrtName. $_server["Query_string"];
}
}
return $nowurl;
}
These examples, in fact, are used in the PHP $_sever global variables to achieve.