15PHP global variables-Super global variables

Source: Internet
Author: User
: This article mainly introduces 15PHP global variables-Super global variables. if you are interested in the PHP Tutorial, refer to it. Hyperglobal variables are built-in variables that are always available in all scopes.

PHP global variables-Super global variables

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.

These super global variables are:

$GLOBALS$_SERVER$_REQUEST$_POST$_GET$_FILES$_ENV$_COOKIE$_SESSION

$ GLOBALS-reference all available variables in the global scope

$ GLOBALS is a global variable used to access global variables (from functions or methods) anywhere in the PHP script ).

PHP stores all global variables in an array named $ GLOBALS [index. The variable name is the key of the array.

The following example shows how to use the Super global variable $ GLOBALS:
Instance


  

PHP $ _ SERVER

The $ _ SERVER Super global variable stores information about the header, path, and script location.

The following example shows how to use some elements in $ _ SERVER:
Instance


  ";echo$_SERVER['SERVER_NAME'];echo"
";echo$_SERVER['HTTP_HOST'];echo"
";echo$_SERVER['HTTP_REFERER'];echo"
";echo$_SERVER['HTTP_USER_AGENT'];echo"
";echo$_SERVER['SCRIPT_NAME'];?>

The following table lists the most important elements that you can access in $ _ SERVER:

PHP $ _ REQUEST

PHP $ _ REQUEST is used to collect data submitted by HTML forms.

The following example shows a form that contains the input field and the submit button. When you click the submit button to submit the form data, the form data is sent
 
  The script file specified in the action attribute of the tag. In this example, we specify the file itself to process form data. If you want to use other PHP files to process form data, change the file name to the one you selected. Then, we can use the Super global variable $ _ REQUEST to collect the value of the input field:
 

Instance


  
   ">Name: 
   
    
     
    
   
  

PHP $ _ POST

PHP $ _ POST is widely used to collect the form data after the HTML form that submits method = "post. $ _ POST is also used to pass variables. The following example shows a form that contains the input field and the submit button. After you click the submit button to submit data, the form data will be sent
 
  The file specified in the action attribute of the tag. In this example, we specify the file itself to process form data. If you want to use another PHP page to process form data, change it to the selected file name. Then, we can use the Super global variable $ _ POST to collect the value of the input field:
 

Instance


  
   ">Name: 
   
    
     
    
   
  

PHP $ _ GET

PHP $ _ GET can also be used to collect the form data after the HTML form (method = "get") is submitted. $ _ GET can also collect data sent from URLs.

Assume that a page contains a hyperlink with parameters:


  
   
Test $ GET
  
When a user clicks the link "Test $ GET", parameters "subject" and "web" are sent to "test_get.php ", then you can access these values through $ _ GET in "test_get.php. The following example shows the code in "test_get.php": instance

  

The above introduces 15 PHP global variables-Super global variables, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.

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.