Usage of $ _ GET, $ _ POST, $ _ REQUEST, and $ _ SERVER in php
-
-
-
-
- Echo $ _ GET ['xingming']."
";
- Echo $ _ GET ['age']."
";
- Echo $ _ POST ['xingming']."
";
- Echo $ _ POST ['age']."
";
- ?>
-
$ _ REQUEST: $ _ REQUEST-HTTP Request variables include $ _ GET, $ _ POST, and $ _ COOKIE arrays by default. If you don't care whether it is get or post, you can use $ _ REQUEST to obtain the value of a key. However, $ _ REQUEST is slower than $ _ GET and $ _ POST. Get SERVER information through $ _ SERVER is an array that contains headers, paths, script locations, and other information. In earlier versions of php, the $ HTTP_server_VARS array is used, and it is no longer used. The $ _ SERVER information of different servers is not necessarily the same. The common usage is as follows:
- Echo $ _ SERVER ['server _ ADDR '];
- Echo $ _ SERVER ['query _ string'];
-
You can use $ _ SERVER ['query _ string'] to obtain QUERY_STRING, such as name = mike & age = 30. To convert the value in this format to a variable, PHP has a method parse_str, which can be used to implement this function. Official example:
- $ Str = "first = value & arr [] = foo + bar & arr [] = baz ";
- Parse_str ($ str );
- Echo $ first; // value
- Echo $ arr [0]; // foo bar
- Echo $ arr [1]; // baz
- Parse_str ($ str, $ output );
- Echo $ output ['first']; // value
- Echo $ output ['arr'] [0]; // foo bar
- Echo $ output ['arr'] [1]; // baz
- ?>
In the local environment, run the following code:
- Echo "";
- Var_dump ($ _ SERVER );
- Echo "";
-
Print the array content with formatted data: Array (31) {["HTTP_ACCEPT"] => string (3) "*/*" ["HTTP_ACCEPT_LANGUAGE"] => string (5) "zh-CN" ["HTTP_USER_AGENT"] => string (205) "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2 ;. net clr 2.0.50727 ;. net clr 3.5.30729 ;. net clr 3.0.30729; Media Center PC 6.0 ;. NET4.0C ;. NET4.0E; InfoPath.2; Avant Browser) "[" HTTP_ACCEPT_ENCODING "] => string (13)" gzip, deflate "[" HTTP_HOST "] => string (14)" localhost: 8080 "[" HTTP_CONNECTION "] => string (10)" Keep-Alive "[" HTTP_COOKIE "] => string (154) "codehilite = IsPre = True & IsShowRowNumber = False & IsUseBR = False & Language = Csharp; iGHA2Cas = key = s8hoPBw6cWYHJ34NowHt % empty" ["PATH"] => string (540) "C: \ Program Files (x86) \ ActiveState Komodo IDE 7 \; C: \ Program Files (x86) \ ActiveState Komodo Edit 7 \; E: \ app \ Administrator \ product \ 11.1.0 \ client_1 \ bin; C: \ Windows \ system32; C: \ Windows \ System32 \ Wbem; C: \ Windows \ System32 \ WindowsPowerShell \ v1.0 \; C: \ Program Files (x86) \ Microsoft SQL Server \ 100 \ Tools \ Binn \; C: \ Program Files \ Microsoft SQL Server \ 100 \ Tools \ Binn \; C: \ Program Files \ Microsoft SQL Server \ 100 \ DTS \ Binn \; C: \ Program Files \ TortoiseSVN \ bin; C: \ Program Files (x86) \ Microsoft asp.net \ ASP. NET Web Pages \ v1.0 \; d: \ php-5.4.4-Win32-VC9-x86 \; "[" SystemRoot "] => string (10)" C: \ Windows "[" COMSPEC "] => string (27)" C: \ Windows \ system32 \ cmd.exe "[" PATHEXT "] => string (53 )". COM ;. EXE ;. BAT ;. CMD ;. VBS ;. VBE ;. JS ;. JSE ;. WSF ;. WSH ;. MSC "[" WINDIR "] => string (10)" C: \ Windows "[" SERVER_SIGNATURE "] => string (0) "" ["SERVER_SOFTWARE"] => string (31) "Apache/2.2.22 (Win32) PHP/5.4.4" ["SERVER_NAME"] => string (9) "localhost" ["SERVER_ADDR"] => string (9) "127.0.0.1" ["SERVER_PORT"] => string (4) & quot; 8080 & quot; [& quot; REMOTE_ADDR & quot;] => string (9) & quot; 127.0.0.1 & quot; [& quot; DOCUMENT_ROOT & quot;] = & quot; string (13) & quot; D: /phpwwwroot "[" SERVER_ADMIN "] => string (11)" dds@wwd.com "[" SCRIPT_FILENAME "] => string (29)" D: /phpwwwroot/RecJP/test2.php "[" REMOTE_PORT "] => string (5)" 23827 "[" GATEWAY_INTERFACE "] => string (7) "CGI/1.1" ["SERVER_PROTOCOL"] => string (8) "HTTP/1.1" ["REQUEST_METHOD"] => string (3) "GET" ["QUERY_STRING"] => string (0) "" ["REQUEST_URI"] => string (16) "/RecJP/test2.php" ["SCRIPT_NAME"] => string (16) "/RecJP/test2.php" ["PHP_SELF"] => string (16) "/RecJP/test2.php" ["REQUEST_TIME_FLOAT"] => float (1351577790572) ["REQUEST_TIME"] => int (-1336907668 )} |