Usage of $ _ GET, $ _ POST, $ _ REQUEST, and $ _ SERVER in php-php Tutorial

Source: Internet
Author: User
Usage of $ _ GET, $ _ POST, $ _ REQUEST, and $ _ SERVER in php

  1. Echo $ _ GET ['xingming']."
    ";
  2. Echo $ _ GET ['age']."
    ";
  3. Echo $ _ POST ['xingming']."
    ";
  4. Echo $ _ POST ['age']."
    ";
  5. ?>

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

  1. Echo $ _ SERVER ['server _ ADDR '];
  2. 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:

  1. $ Str = "first = value & arr [] = foo + bar & arr [] = baz ";
  2. Parse_str ($ str );
  3. Echo $ first; // value
  4. Echo $ arr [0]; // foo bar
  5. Echo $ arr [1]; // baz
  6. Parse_str ($ str, $ output );
  7. Echo $ output ['first']; // value
  8. Echo $ output ['arr'] [0]; // foo bar
  9. Echo $ output ['arr'] [1]; // baz
  10. ?>

In the local environment, run the following code:

  1. Echo "";
  2. Var_dump ($ _ SERVER );
  3. 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 )}

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.