Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Superglobals

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 175
    Comment on it

    PHP Superglobals are always accessible regardless of their scope, i.e., we can access them from any function, class or a file without even declaring them. Superglobals are available in all scopes throughout a script. There is no need to do global $variable; to access then within functions or methods. The PHP Superglobals represent data coming from URLs, HTML forms, cookies, sessions, and the Web server itself.

     

    Following are the Superglobals in PHP:

     

    1. $_GET – is used to collect the data from the form while submitting an HTML from with get method. It is also used to collect data which is sent in the url.
       

    2. $_POST - is used to collect the data from the form while submitting an HTML from with post method. It is also used to pass variables.
       

    3. $_REQUEST – is used to collect data after submitting an HTML form. The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms.
       

    4. $_SERVER – is an array containing information such as headers, paths, and script locations. Entries in this array are created by the web server

       List of important elements that can go inside $_SERVER:

     

     

    Element/Code Description                      

    $_SERVER['PHP_SELF']

    Returns the filename of the currently executing script

    $_SERVER['SERVER_PORT']

    Returns the port on the server machine being used by the web server for communication (such as 80)

    $_SERVER['HTTP_HOST']

    Returns the Host header from the current request

    $_SERVER['HTTPS']

    Is the script queried through a secure HTTP protocol

    $_SERVER['REMOTE_ADDR']

    Returns the IP address from where the user is viewing the current page

    $_SERVER['REMOTE_HOST']

    Returns the Host name from where the user is viewing the current page

    $_SERVER['GATEWAY_INTERFACE']

    Returns the version of the Common Gateway Interface (CGI) the server is using

    $_SERVER['SERVER_ADDR']

    Returns the IP address of the host server

    $_SERVER['SERVER_NAME']

    Returns the name of the host server

    $_SERVER['SERVER_PROTOCOL']

    Returns the name and revision of the information protocol (such as HTTP/1.1)

    $_SERVER['REQUEST_METHOD']

    Returns the request method used to access the page (such as POST)

    $_SERVER['REQUEST_TIME']

    Returns the timestamp of the start of the request

    $_SERVER['HTTP_ACCE]

     

    Returns the Accept header from the current request

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: