Home >Backend Development >PHP Tutorial >php Get the complete url address_PHP tutorial

php Get the complete url address_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:48:00995browse

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" ];

www.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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn