This paper introduces the functions of getting the current URL path in PHP, and some server variables in PHP, which can be used for reference by friends in need. Mainly used in these several: $_server["query_string"],$_server["Request_uri"],$_server["Script_name"],$_server["PHP_SELF"] 1,$_server["Query_string"] Description: A string that queries (query) 2,$_server["Request_uri"] Description: The URI required to access this page 3,$_server["Script_name"] Description: Contains the path of the current script 4,$_server["Php_self"] Description: The file name of the currently executing script Example: 1,http://bbs.it-home.org/(open homepage directly) results: $_server["query_string"] = "" $_server["request_uri"] = "/" $_server["script_name"] = "/index.php" $_server["PHP_SELF"] = "/index.php"
2,http://bbs.it-home.org/?p=222 (with query) results: $_server["query_string"] = "p=222" $_server["request_uri"] = "/?p=222" $_server["script_name"] = "/index.php" $_SERVER[ "Php_self"] = "/index.php"
3,HTTP://BBS.IT-HOME.ORG/INDEX.PHP?P=222&Q=BIUUU results: $_server["query_string"] = "p=222&q=biuuu" $_server["request_uri"] = "/index.php?p=222&q=biuuu" $_SERVER[" Script_name "] ="/index.php "$_server[" php_self "] ="/index.php "$_server[" query_string "] gets the query statement, in the instance, gets the following value $_server["Request_uri"] gets the value after http://bbs.it-home.org, including/$_server["Script_name"] gets the path of the current script, such as: index.php$_server[" Php_self "] The file name of the script that is currently executing
Current URL: "/http". $_server[' http_host '].$_server[' php_self '] Summary: Suggest an in-depth understanding of query_string,request_uri,script_name and php_self. It is recommended to understand the difference between the four variables in Query_string,request_uri,script_name and php_self in the $_server function. $_server["Request_uri"]: Gets the full (except domain) URL of the current request ... Uchome processing techniques in the system: Processing Request_uriif (!isset ($_server[' Request_uri ')) {$_server[' Request_uri '] = $_server[' php_self ']; if (Isset ($_server[' query_string ')) $_server[' Request_uri ']. = '? '. $_server[' query_string ');} if ($_server[' Request_uri ') { $temp = UrlDecode ($_server[' Request_uri ']); if (strexists ($temp, ' < ') | | strexists ($temp, ' "')) { $_get = Shtmlspecialchars ($_get);//XSS }}
"; Get the server document root variable echo $_server[' Php_self ']. "; Get the variable echo __file__ for the absolute path of the file server that executes the code. "; Gets the file-system absolute path of the variable echo dirname (__file__); function to get the folder path where the file is located?>
The SERVER function $_server["http_referer"]=http://localhost/lianxi/$_server["Http_accept_language"]=zh-cn$_SERVER[" Http_accept_encoding "]=gzip, deflate$_server[" Http_user_agent "]=mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;. NET CLR 1.1.4322;. NET CLR 2.0.50727) $_server["Http_host"]=localhost$_server["Http_connection"]= keep-alive$_server["PATH"]=C:\WINDOWS\SYSTEM32; C:\WINDOWS; C:\WINDOWS\System32\Wbem; C:\Program Files\Common Files\adobe\agl; C:\Program files\mysql\mysql Server 5.0\bin; C:\php; c:\php\ext$_server["SystemRoot"]=c:\windows$_server["COMSPEC"]=c:\windows\system32\cmd.exe$_server["PATHEXT"]= . COM;. EXE;. BAT;. CMD;. VBS;. VBE;. JS;. JSE;. WSF;. wsh$_server["windir"]=c:\windows$_server["Server_signature"]=apache/2.0.55 (Win32) php/5.1.1 SERVER at localhost Port 80 \ \ What server is used $_server["Server_software"]=apache/2.0.55 (Win32) php/5.1.1$_server["SERVER_NAME"]=localhost \ \ Server name $_server["server_addr"]=127.0.0.1$_server["server_port"]=80 \ \ Server Port $_server["REMOTE_ADDR"]=127.0.0.1$_ server["Document_rooT "]=d:/lianxi \ \ \ \ \ \ \" $_server["Server_admin"]=sss@163.com the mailbox $_server["Script_filename" When you install Apache]=d:/lianxi /lianxi/servervalues.php \ \ The absolute path of the current Web page, $_server["remote_port"]=1076 \ \ Remote Port $_server["Gateway_interface"]=CGI/1.1$_ server["Server_protocol"]=http/1.1$_server["Request_method"]=get$_server["query_string"]=\\ get? After the $_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 page. $_server["Request_time"]=1179190013 \ \ Run time unit is one out of 10,000 milliseconds $_server["argv"]=array$_server["argc"]=01,$_server["query_string" description: Query string 2,$_server[" Request_uri "] Description: The uri3,$_server[" script_name "description required to access this page: Contains the path of the current script 4,$_server[" php_self "description: The file name of the currently executing script
"; echo" GETCWD: ", GETCWD ()," "Echo" __file__: ", __file__," "; echo" Request_uri: ", $_server[" Request_uri "]," "; echo" Script_name: ", $_server[" Script_name "]," "; echo" Php_self: ", $_server[" php_self "]," "Echo" Script_filename ", $_server[" Script_filename "]," ";//The test2.php included in the test2.php output the above variables, see what is different: include_once (" test2/test2.php "); > The above is the full content of the PHP tutorial today, something a bit more, a bit messy, but it is really good things, we have to learn the nutrition of knowledge, hehe. |