We have many functions that we can use to get the url address in php. The main thing is that the global variable server provides me with many methods. Let’s take a look.
//Get user agent
echo $_SERVER['HTTP_REFERER']."
";
//Get the complete url
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
#http://localhost/blog/testurl.php?id=5
//Full url including port number
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
#http://www.bKjia.c0m /blog/testurl.php?id=5
//Get only the path
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
#http://localhost/blog
Look at an example to get the complete url
The code is as follows
|
Copy code
|
<🎜>function curpageurl()
{
$pageurl = 'http';<🎜>
<🎜> if ($_server["https"] == "on")
{
$pageurl .= "s";
}
$pageurl .= "://";<🎜>
<🎜> if ($_server["server_port"] != "80")
{
$pageurl .= $_server["server_name"] . ":" . $_server["server_port"] . $_server["request_uri"];
}
else
{
$pageurl .= $_server["server_name"] . $_server["request_uri"];
}
Return $pageurl;
}
?>
http://www.bkjia.com/PHPjc/632634.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632634.htmlTechArticleWe have many functions to use to get the url address in php, mainly the global variable server provides me with a lot Method, let’s take a look below. Commonly used function codes are as follows. Copy...
|