PHP $_SERVER current full url

  • 2020-03-31 16:43:09
  • OfStack


"http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; 


PHP server functions
SERVER [' HTTP_ACCEPT "] = * / *
$_SERVER [" HTTP_REFERER "] = http://localhost/lianxi/
"HTTP_ACCEPT_LANGUAGE" $_SERVER [] = useful - cn
$_SERVER [" HTTP_ACCEPT_ENCODING "] = gzip, deflate
$_SERVER [" HTTP_USER_AGENT "] = Mozilla / 4.0 (compatible; MSIE 6.0; Windows NT 5.2; The.net CLR 1.1.4322; The.net CLR 2.0.50727)
$_SERVER [" HTTP_HOST "] = localhost
$_SERVER [" HTTP_CONNECTION "] = Keep - the Alive
$_SERVER [" PATH "] = C: \ WINDOWS \ system32; C: \ WINDOWS; C: \ WINDOWS \ System32 \ Wbem; C: \ Program Files \ Common Files \ Adobe \ AGL. C: \ Program Files \ MySQL 5.0 \ bin \ MySQL Server; C: \ PHP. C: \ PHP \ ext
"SystemRoot" $_SERVER [] = C: \ WINDOWS
"COMSPEC" $_SERVER [] = C: \ WINDOWS \ system32 \ CMD exe
"] = $_SERVER [" PATHEXT. COM. .exe; . BAT; . CMD; . VBS; . VBE varies; .js; . The JSE; . WSF; . WSH
"WINDIR" $_SERVER [] = C: \ WINDOWS
= $_SERVER [" SERVER_SIGNATURE "]
Apache/2.0.55 (Win32) PHP/5.1.1 Server at localhost Port 80 \\
"SERVER_SOFTWARE" $_SERVER [] = Apache / 2.0.55 PHP / 5.1.1 (Win32)
$_SERVER["SERVER_NAME"]=localhost \\ server name
"SERVER_ADDR" $_SERVER [] = 127.0.0.1
$_SERVER["SERVER_PORT"]=80 \\ server port
"REMOTE_ADDR" $_SERVER [] = 127.0.0.1
$_SERVER["DOCUMENT_ROOT"]=D:/lianxi \ directory
$_SERVER["SERVER_ADMIN"]=sss@163.com \
"SCRIPT_FILENAME" $_SERVER [] = D: / lianxi/lianxi/servervalues. PHP \ \ the current web page the absolute path,
$_SERVER["REMOTE_PORT"]=1076 \\ remote port
"] = $_SERVER [' GATEWAY_INTERFACE CGI / 1.1
$_SERVER [" SERVER_PROTOCOL "] = HTTP / 1.1
= GET $_SERVER [" REQUEST_METHOD "]
$_SERVER [" QUERY_STRING "] = \ \ get? After the number
$_SERVER["REQUEST_URI"]= example: /lianxi/servervalues.php? A = 1 & b = 2
$_SERVER["SCRIPT_NAME"]= example: /lianxi/servervalues.php
$_SERVER["PHP_SELF"]=/lianxi/servervalues.php \ returns the relative path of the current web page.
$_SERVER["REQUEST_TIME"]=1179190013 \ run time in milliseconds
"Argv" $_SERVER [] = Array
$_SERVER [" arg c "] = 0
Note: the main directory of the website that returns this result is D:/lianxi
< ? PHP
The foreach ($_SERVER as $asd = > $values)
{
Echo (" \ $_SERVER [\ "$asd \] =". $values. "< / p>" );
}

$_SERVER stores the current server information, among which there are several values such as $_SERVER["QUERY_STRING"], $_SERVER["REQUEST_URI"], $_SERVER["SCRIPT_NAME"] and $_SERVER["PHP_SELF"], which are often confused. Master the relationship between the four, so as to correctly obtain the required value in the practical application, for reference.



1, $_SERVER [" QUERY_STRING "]
The string of the query

2, the $_SERVER [" REQUEST_URI "]
Description: the URI required to access this page

3, the $_SERVER [" SCRIPT_NAME "]
Contains the path to the current script

4, $_SERVER [" PHP_SELF "]
Name of the script currently executing

Example:
1, http://www.biuuu.com/ (direct to the home page)
Results:
$_SERVER [" QUERY_STRING "] = ""
"REQUEST_URI" $_SERVER [] = "/"
$_SERVER [" SCRIPT_NAME "] = "/ index. PHP"
"PHP_SELF" $_SERVER [] = "/ index. PHP"

2, http://www.biuuu.com/? P =222 (with query)
Results:
$_SERVER [" QUERY_STRING "] = "p = 222"
"REQUEST_URI" $_SERVER [] = "/? P = 222"
$_SERVER [" SCRIPT_NAME "] = "/ index. PHP"
"PHP_SELF" $_SERVER [] = "/ index. PHP"

3, http://www.biuuu.com/index.php? P = 222 & q = biuuu
Results:
"QUERY_STRING" $_SERVER [] = "p = 222 & q = biuuu"
"REQUEST_URI" $_SERVER [] = "/ index. PHP? P = 222 & q = biuuu"
$_SERVER [" SCRIPT_NAME "] = "/ index. PHP"
"PHP_SELF" $_SERVER [] = "/ index. PHP"

$_SERVER["QUERY_STRING"] gets the query statement. The value behind the
$_SERVER["REQUEST_URI"] gets the value after http://www.biuuu.com, including /
$_SERVER["SCRIPT_NAME"] gets the path to the current script, such as index.php
$_SERVER["PHP_SELF"] the file name of the script currently executing

To summarize, for QUERY_STRING, REQUEST_URI, SCRIPT_NAME, and PHP_SELF, a deeper understanding will help us to call the four values correctly in the $_SERVER function. Learn the difference between QUERY_STRING, REQUEST_URI, SCRIPT_NAME, and PHP_SELF in the $_SERVER function by example.

Related articles: