It mainly obtains some information about the address bar, domain names, port parameters, etc.
CopyCode The Code is as follows: <? PHP
// Obtain the domain name or host address
Echo $ _ server ['HTTP _ host']. "<br> ";
// Obtain the webpage address
Echo $ _ server ['php _ Self ']. "<br> ";
// Obtain URL parameters
Echo $ _ server ["QUERY_STRING"]. "<br> ";
// Detailed address of the source webpage
Echo $ _ server ['HTTP _ referer']. "<br> ";
?>
PHP obtains the current Script URL (only path)Copy codeThe 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)Copy codeThe 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 containing the port path copy Code the code is as follows: Echo 'HTTP ://'. $ _ server ['server _ name']. ':'. $ _ server ["server_port"]. $ _ server ["request_uri"];