Php introduction to getting current url path functions and server variables-php Tutorial

Source: Internet
Author: User
Tags php introduction
Php introduction to getting current url path functions and server variables
We will introduce the functions for getting the current url path in php and some server variables in php for your reference.

Mainly used: $ _ SERVER ["QUERY_STRING"], $ _ SERVER ["REQUEST_URI"], $ _ SERVER ["SCRIPT_NAME"], $ _ SERVER ["PHP_SELF"]

1, $ _ SERVER ["QUERY_STRING"] description: query string

2, $ _ SERVER ["REQUEST_URI"] description: the URI required to access this page

3, $ _ SERVER ["SCRIPT_NAME"] description: path containing the current script

4, $ _ SERVER ["PHP_SELF"] description: file name of the script being executed

Instance: 1, http://bbs.it-home.org/(directly open the home page) result:

$_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) result:

$_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 result:

$ _ 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 "]: obtain the query statement. Which of the following statements is obtained in the instance? The following value $ _ SERVER ["REQUEST_URI"] gets the value after the http://bbs.it-home.org, including/$ _ SERVER ["SCRIPT_NAME"] to get the path of the current script, such as index. php $ _ SERVER ["PHP_SELF"] file name of the script currently being executed

Current url: "http: //". $ _ SERVER ['http _ host']. $ _ SERVER ['php _ SELF ']

Conclusion: We recommend that you have a deep understanding of QUERY_STRING, REQUEST_URI, SCRIPT_NAME, and PHP_SELF. We recommend that you thoroughly understand the differences between the four variables in the $ _ SERVER function: QUERY_STRING, REQUEST_URI, SCRIPT_NAME, and PHP_SELF.

$ _ SERVER ["REQUEST_URI"]: get the complete (except the domain name) url of the current request...

Uchome system processing skills:

// Process 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 }}
     "; // Obtain the SERVER document root variable echo $ _ SERVER ['php _ SELF ']."
"; // Obtain the echo _ FILE _ variable in the absolute path of the FILE server that executes the code __."
"; // Echo dirname (_ FILE _) variable for obtaining the absolute path of the FILE system; // Function for obtaining the path of the folder where the FILE is located?>

// 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 \ System32 \ Wbem; C: \ Program Files \ Common Files \ Adobe \ AGL; C: \ Program Files \ M YSQL \ MySQL Server 5.0 \ bin; 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 \ which 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 \ main directory of the website $ _ SERVER ["SERVER_ADMIN"] = sss@163.com \ mailbox set when installing APACHE $ _ SERVER ["SCRIPT_FILENAME"] = D: /lianxi/servervalues. php \ absolute path of the current webpage, $ _ 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? $ _ 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 webpage. $ _ SERVER ["REQUEST_TIME"] = 1179190013 \ the unit of running time is 100,000 in milliseconds $ _ SERVER ["argv"] = Array $ _ SERVER ["argc"] = 01, $ _ SERVER ["QUERY_STRING"] description: query string 2, $ _ SERVER ["REQUEST_URI"] description: URI3, $ _ SERVER ["SCRIPT_NAME"] description: Path 4 containing the current script, $ _ SERVER ["PHP_SELF"] description: file name of the script being executed

     "; 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 "],"
"; // Include test2.php and output the above variable in test2.php. what is the difference: include_once (" test2/test2.php ");?>

The above is all the content of today's php Tutorial. There are a lot of things and chaos, but they are really good things. let's learn about the nutrition with your heart, huh, huh.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.