PHP gets the current page URL function instance, gets the current url function
This article describes an example of the PHP function to obtain the URL of the current page and shares it with you for your reference. The specific implementation method is as follows:
In PHP, there is no default Function to get the URL of the current page, so today I will introduce to you a PHP function that gets the complete URL of the current page in PHP.
The function code is as follows, you only need to use curPageURL() when calling:
Copy code The code is as follows:
/* Get the start of the current page URL */
function curPageURL() {
$pageURL = 'http';
If ($_SERVER["HTTPS"] == "on") { // If it is SSL encryption, add "s"
$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;
}
/* Get the end of the current page URL */
Add the server parameter description, the code is as follows:
Copy code The code is as follows:
//Get the domain name or host address
echo $_SERVER['HTTP_HOST']."
"; #localhost
//Get the web address
echo $_SERVER['PHP_SELF']."
"; #/blog/testurl.php
//Get URL parameters
echo $_SERVER["QUERY_STRING"]."
"; #id=5
//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://localhost:80/blog/testurl.php?id=5
//Only get the path
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
#http://localhost/blog
I hope this article will be helpful to everyone’s PHP programming design.
You can take a look at this:
A.php:
Click me first, then pay attention to the URLClick I go to b.phpB.php:
echo 'The URL of the web page just now is:'.$_SERVER['HTTP_REFERER'];
?>
------------------------------------------------ ----------------------------
.$_SERVER['HTTP_REFERER'];
Get the previous URL
//Get the current page url
$url_this = "http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF'];
echo $url_this;
//Page jump
$url =" www.baidu.com/2.php";
< html>
< head>
< meta http-equiv=" refresh" content="1; url=< ?php echo $url; ?>">
< /head>
?>
http://www.bkjia.com/PHPjc/897686.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/897686.htmlTechArticlePHP gets the current page URL function instance, gets the current url function. The example in this article tells about the PHP getting the current page URL function instance. Share it with everyone for your reference. The specific implementation method is as follows:...