Home > Article > Backend Development > Usage of $_GET, $_POST, $_REQUEST and $_SERVER in php
$_REQUEST: $_REQUEST — The HTTP Request variable contains an array of $_GET, $_POST, and $_COOKIE by default. Regardless of whether it comes from get or post, if you want to get the value of a certain key, just use $_REQUEST. However, the speed of $_REQUEST will be slightly slower than $_GET and $_POST. Get server-side information through $_SERVER $_SERVER is an array that contains headers, paths, script locations and other information. Earlier versions of PHP used the $HTTP_server_VARS array, which is now deprecated. The information of $_SERVER on different servers is not necessarily the same. Common usage is as follows:
The more common way to get QUERY_STRING is through $_SERVER['QUERY_STRING '] What you get is something like name=mike&age=30. To convert values in this format into variables, there is a method parse_str in PHP that can achieve this function. Official example:
pass the code in the local environment:
用带格式的数据打印出数组内容: 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%2f77gsEiQ9U9K0dDGPYjwLCFzQbqnNjlYMnUw9OOCF68u" ["PATH"]=> string(540) "C:Program Files (x86)ActiveState Komodo IDE 7;C:Program Files (x86)ActiveState Komodo Edit 7;E:appAdministratorproduct11.1.0client_1bin;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Files (x86)Microsoft SQL Server100ToolsBinn;C:Program FilesMicrosoft SQL Server100ToolsBinn;C:Program FilesMicrosoft SQL Server100DTSBinn;C:Program FilesTortoiseSVNbin;C:Program Files (x86)Microsoft asp.netASP.NET Web Pagesv1.0;d:php-5.4.4-Win32-VC9-x86;" ["SystemRoot"]=> string(10) "C:Windows" ["COMSPEC"]=> string(27) "C:Windowssystem32cmd.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) "8080" ["REMOTE_ADDR"]=> string(9) "127.0.0.1" ["DOCUMENT_ROOT"]=> string(13) "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) } |