We have summarized multiple methods for php to fully obtain url address bar parameters. All of them use the function server provided by php. Here we have summarized multiple methods for php to fully obtain url address bar parameters, all of them use the built-in function server of php.
Script ec (2); script
| 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']."
";
?> |
Method 2? Expression,
| The Code is as follows: |
|
| Echo 'HTTP ://'. $ _ SERVER ['server _ name']. ':'. $ _ SERVER ["SERVER_PORT"]. $ _ SERVER ["REQUEST_URI"]; |
Method 3 is the same
| 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 (); |
Method 4: Obtain the url parameters comprehensively. First, use REQUEST_URI. If the server does not support the parameters, use PHP_SELF.
| The Code is as follows: |
|
QUERY_STRING
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;
} |
The above instances are actually implemented using the php $ _ SEVER global variable.