It mainly obtains some information about the address bar, domain names, port parameters, etc.
Copy codeThe 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, including the port path.
Copy codeThe Code is as follows:
Echo 'HTTP ://'. $ _ SERVER ['server _ name']. ':'. $ _ SERVER ["SERVER_PORT"]. $ _ SERVER ["REQUEST_URI"];