Mainly get some information from the address bar, domain name, port parameters, etc.
Copy the code The code is as follows:
//Get the domain name or host address
echo $_SERVER['HTTP_HOST']."
";
//Get the web page address
echo $_SERVER['PHP_SELF ']."
";
//Get the URL parameters
echo $_SERVER["QUERY_STRING"]."
";
//The detailed address of the source webpage
echo $_SERVER['HTTP_REFERER']."
";
?>
php Get the current script URL (only path)
Copy code The code is as follows:
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;
}
//Instance call method
//echo GEtCurUrl();
php gets the url address without path (domain name or ip address)
Copy code The code is as follows:
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 call method
echo getServerName();
php gets the url address including the port path
Copy code The code is as follows:
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI" ];
http://www.bkjia.com/PHPjc/319866.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319866.htmlTechArticleMainly get some information from the address bar, domain name, port parameters, etc. Copy the code code as follows: ?php // Get the domain name or host address echo $_SERVER['HTTP_HOST']."br"; //Get the web page address...