Android Programmer learns PHP Development (22)-Hyper Global array/Hyper global variable-phpstorm

Source: Internet
Author: User
Tags http cookie http file upload http post learn php php server setcookie
The PHP Super global variable Array (super Global Array), also known as the PHP predefined array, is built into the PHP engine and does not need to be redefined by the developer. PHP will automatically put some data in the Super Global array when the PHP script is running.

Many of the predefined variables in PHP are "hyper-global", which means they are available in all scopes of a script. There is no need to perform a global $variable in a function or method; You can access them.

PHP Super Global Variables list:

$_get[] Get an array of variables submitted with the Get method

$_post[] Get an array of variables submitted with the POST method

$_cookie[] Get and set the COOKIE ID of the current Web site

$_session[] A unique identifier for the current user access, expressed as an array, such as SessionID and custom SESSION data

$_env[] Current PHP environment variable array

$_server[] array of current PHP server variables

$_files[] A parameter value submitted to the current script when uploading a file, as an array

$_request[] contains all requests submitted by the current script, $_get, $_post, $_cookie all actions

$GLOBALS [] contains references to all super global variables that are executing the script

index.php:

<?php/** * Hyper Global array/Hyper global variable * Many of the predefined variables in PHP are "hyper-global", which means they are available in all scopes of a script. * There is no need to perform global $variable in functions or methods;     You can access them.      * These hyper-global variables are: $_globals global variable $_server server variable $_request REQUEST variable $_post        HTTP POST variable $_get http GET variable $_files http file upload variable $_env environment variable $_cookie    HTTP Cookies $_session SESSION variable */echo getip ();    echo "<br>";    Echo Getip2 ();    echo "<br>"; /** * Traversal $_server array */foreach ($_server as $key + = $value) {echo "{$key} + {$value} <br>"    ;    }/** * Server IP function--written 0 minutes of writing */function GetIP () {return $_server[' remote_addr ']; }/** * Server IP function--correct notation */function getip2 () {if (!empty ($_server[' http_client_ip ')) {Retu        RN $_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 */<br> <a href= "demo.php?action=add&id=5&name=admin" > Test page & lt;/a><br>/** * POST * nickname[] bidding clubs self-increment, no difference from array */<br> <form action= "Demo.php?nick=ww W&psw=yyy "method=" POST "> Nickname:<input type=" text "Name=" nickname[] "/><br> NICKNAME:&L T;input type= "text" Name= "nickname[]"/><br> nickname:<input type= "text" Name= "nickname[]"/><br&gt        ; Nickname:<input type= "text" Name= "nickname[9]"/><br> nickname:<input type= "text" Name= "nickname[]"/& gt;<br> nickname:<input type= "text" Name= "nickname[x]"/><br> nickname:<input type= "text "Name=" nickname[] "/><br> username:<input type=" text "name=" name "/><br> age:&Lt;input type= "text" name= "age"/><br> sex:<input type= "text" name= "Sex"/><br> <input      Type= "Submit" Name= "sub" value= "Commit" > </form><br><?php/** * $_session * * SESSION function: * http://www.php.cn/* Session start, save, End: * http://www.php.cn/*/echo '----------$_session----    ------<br> '; Session_Start ();    Start a new session or reuse an existing conversation $_session[' name ']= "Hello"; Print_r ($_session); Print Result: Array ([name] = = Hello) session_unset (); Release all session variables Session_destroy ();                        Destroys all data in the current session, but does not reset the global variables associated with the current session, nor resets the session cookie. If you need to use the session variable again, you must recall the session_start () function session_write_close (); Ends the current session and stores 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 with the new ID without modifying the data in the current session echo "<br>"; /** * $GLOBALS referencing all changes available in the global scopeVolume * A globally combined array that contains all the variables.     The name of the variable is the key of the array.    */Echo '----------$GLOBALS----------<br> ';    echo "<pre>"; Print_r ($GLOBALS); Print all the above results echo "</pre>";

demo.php: (for use with index.php)

<?php    /**     * $_get can only be answered by GET *    /Print_r ($_get);    echo "<br>";    Print_r ($_get[' action ');    echo "<br>";    /**     * $_post can only be received POST *    /Print_r ($_post);    echo "<br>";    /**     * $_request can connect get and POST     * However, it is easy to be hacked, because everything can be answered     * So need get to use $_get, need POST to use $_post     * Ignore $_ The existence of the REQUEST     *    /Print_r ($_request);    echo "<br>";    /**     * Not sure get or POST     * can use the following notation *    /$arr =!empty ($_post)? $_post: $_get;

The above is the Android programmer to learn PHP development (22)-Super Global array/Super global variable-phpstorm content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.