PHP Super global variable array (SuperGlobalArray), also known as PHP pre-defined array, is built in by the PHP engine and does not need to be redefined by developers. When the PHP script runs, PHP automatically puts some data in the Super Global array. PHP Super Global variable Array (Super Global Array), also known as PHP pre-defined Array, is built in by the PHP engine and does not need to be redefined by developers. When the PHP script runs, PHP automatically puts some data in the Super Global array.
Many predefined variables in PHP are "super Global", which means they are available in all scopes of a script. You can access functions or methods without performing global $ variable.
Php Super global variable list:
$ _ GET [] GET the variable array submitted using the GET method
$ _ POST [] get the variable array submitted using the POST method
$ _ COOKIE [] obtain and set the Cookie ID of the current website
$ _ SESSION [] gets the unique identifier of the current user's access, represented in arrays, such as sessionid and custom session data.
$ _ ENV [] Current php environment variable array
$ _ SERVER [] Current php SERVER variable array
$ _ FILES [] parameter values submitted to the current script during file upload, in array format
$ _ REQUEST [] contains all the requests submitted by the current script, all the actions of $ _ GET, $ _ POST, and $ _ COOKIE.
$ GLOBALS [] contains references to all Super global variables in the script being executed
Index. php:
"; Echo getip2 (); echo"
";/*** Traverse $ _ SERVER array */foreach ($ _ SERVER as $ key =>$ value) {echo" {$ key }=>{$ value}
";}/*** Server ip address function-written statement of 0 points */function getip () {return $ _ SERVER ['remote _ ADDR '];} /*** server IP function-correct syntax */function getip2 () {if (! Empty ($ _ SERVER ['http _ CLIENT_IP ']) {return $ _ SERVER ['http _ CLIENT_IP'];} elseif (! Empty ($ _ SERVER ['http _ X_FORWARDED_FOR ']) {return $ _ SERVER ['http _ X_FORWARDED_FOR'];} elseif (! Empty ($ _ SERVER ['remote _ ADDR ']) {return $ _ SERVER ['remote _ ADDR'];} else {return 'unknown IP' ;}}?> /*** GET */
Test page
/*** POST * nickname [] subscript will be auto-incrementing, no difference from array */
'; Session_start (); // start a new SESSION or reuse an existing SESSION $ _ SESSION ['name'] = "hello"; print_r ($ _ SESSION); // print the result: array ([name] => hello) session_unset (); // release all session variables session_destroy (); // destroy all data in the current session, however, the global variables associated with the current session are not reset, and the session cookie is not reset. // If you need to use the session variable again, you must re-call the session_start () function session_write_close (); // end the current session and store the session data setcookie (session_name (), '', 0, '/'); // session_name-read/set session name // setcookie () function sends an HTTP cookie to the client. Session_regenerate_id (true); // replace the original session ID echo with the new ID without modifying the data in the current session"
";/*** $ GLOBALS references all the variables available in the global scope * a global combination array containing all the variables. The variable name is the key of the array. */Echo '---------- $ GLOBALS ----------
'; Echo""; Print_r ($ GLOBALS); // print all the above results echo"
";
Demo. php: (used with index. php)
"; Print_r ($ _ GET ['action']); echo"
";/*** $ _ POST can only be followed by post */print_r ($ _ POST); echo"
";/*** $ _ REQUEST can be connected to get and post *, but it is easy to be attacked by hackers. because everything can be connected *, you need to get $ _ GET, if post is required, use $ _ POST * to ignore the existence of $ _ REQUEST */print_r ($ _ REQUEST); echo"
";/*** You are not sure whether get or post * can use the following method */$ arr =! Empty ($ _ POST )? $ _ POST: $ _ GET;
The above is the content of PHP Development (22)-Ultra Global array/Ultra Global variable-PhpStorm for Android programmers. For more information, see PHP Chinese network (www.php1.cn )!