Usage of $_get,$_post,$_request and $_server in PHP

Source: Internet
Author: User
    1. echo $_get[' xingming ']. "
      ";
    2. echo $_get[' age ']. "
      ";
    3. echo $_post[' xingming ']. "
      ";
    4. echo $_post[' age ']. "
      ";
    5. ?>
Copy Code

$_request's official note: The $_request-http REQUEST variable contains an array of $_get,$_post and $_cookie by default. Do not care is get come over or post, in short to get a key value, you can use $_request. But the $_request speed will be slightly slower than the $_get,$_post. Obtaining server-side information via $_server $_server is an array that contains headers, paths, script locations and many other information. Earlier versions of PHP used the $http_server_vars array, which is now deprecated. Different server $_server information is not necessarily the same. The usual usage is as follows:

    1. echo $_server[' server_addr '];
    2. echo $_server[' query_string '];
Copy Code

The more commonly used methods of obtaining query_string are obtained by $_server[' query_string ') such as name=mike&age=30. In order to convert the value of this format into a variable, PHP has a method parse_str, which can implement this function. An 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. ?>
Copy Code

In the local environment by code:

    1. echo "";
    2. Var_dump ($_server);
    3. echo "";
Copy Code

Print an array of content in formatted data:

Array (+) {["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 (All)" gzip, deflate "[" Http_host "]=> string" localhost:8080 "[" Http_connection "]=> string (Ten)" Keep-alive "[" Http_cookie "]=> string (154)" codehilite=ispre=true& isshowrownumber=false&isusebr=false&language=csharp; Igha2cas=key=s8hopbw6cwyhj34nowht%2f77gseiq9u9k0ddgpyjwlcfzqbqnnjlymnuw9oocf68u "[" 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; 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 (Ten) "C:\Windows" ["COMSPEC"]=> string "C:\Windows\system32\cmd.exe" ["Pathext"]= > string (+) ". COM;. EXE;. BAT;. CMD;. VBS;. VBE;. JS;. JSE;. WSF;. WSH;. MSC "[" windir "]=> String (Ten)" 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)" 8080 "[" REMOTE_ADDR "]=> string (9)" 127.0.0.1 "[" Document_root "]=> String "D:/phpwwwroot" ["Server_admin"]=> string (one) "dds@wwd.com" ["Script_filename"]=> string "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 (+)"/recjp/test2.php "[" Script_name "]=> string (+)"/recjp/ Test2.php "[" Php_self "]=> string (+)"/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.