This article describes the PHP to get the current page URL function example, share for everyone to reference. The implementation methods are as follows:
In PHP, there is no default function to get the URL of the current page, so today we're going to introduce you to a PHP function that gets the full URL of the current page in PHP.
The function code is as follows, the call only need to use Curpageurl () on the line:
Copy Code code as follows:
/* Get the current page URL start * *
function Curpageurl () {
$pageURL = ' http ';
if ($_server["HTTPS"] = = "on") {//If SSL encryption plus "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 current Page URL End * *
To add the server parameter description, the code is as follows:
Copy Code code as follows:
Echo $_server[' Http_host ']. " <br> "; #localhost
//Get page address
Echo $_server[' php_self ']. " <br> "; #/blog/testurl.php
//Get URL parameters
echo $_server["Query_string"]. " <br> "; #id =5
//Get user agent
Echo $_server[' Http_referer ']. " <br> ";
//Get the full 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 containing port number
Echo ' http://'. $_server[' server_name ']. ': '. $_server["Server_port"].$_server["Request_uri"];
#http://localhost:80/blog/testurl.php?id=5
//Only fetch path
$url = ' http://'. $_server[' server_name '].$_server[' Request_uri '];
Echo dirname ($url);
#http://localhost/blog
I hope this article will help you with your PHP program design.