Phpurl obtains parameters, ports, and other information. later, it is supplemented by the script. after testing, it is a function code that can be directly used. It mainly obtains some information about the address bar, domain names, port parameters, etc.
The code is as follows:
// Obtain the domain name or host address
Echo $ _ SERVER ['http _ host']."
";
// Obtain the webpage address
Echo $ _ SERVER ['php _ SELF ']."
";
// Obtain URL parameters
Echo $ _ SERVER ["QUERY_STRING"]."
";
// Detailed address of the source webpage
Echo $ _ SERVER ['http _ referer']."
";
?>
Php obtains the current script URL (only Path)
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 retrieves url addresses without paths (domain names or IP addresses)
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 obtains the url address, including the port path.
The code is as follows:
Echo 'http ://'. $ _ SERVER ['server _ name']. ':'. $ _ SERVER ["SERVER_PORT"]. $ _ SERVER ["REQUEST_URI"];