Getting Started with PHP (V)

First, the super globals

  Super global variables are enabled after PHP 4.1.0, PHP is the system comes with variables, all scopes in a script are available.  

  PHP predefined several super-global variables (superglobals), which means that they all scopes in a script are available. You do not need special instructions, you can use the functions and classes.

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

  1.  $ GLOBALS is a combination of an array that contains all global variables. The key variable is the name of the array.

  Example:

  <?php
    $x = 75;
    $y = 25;

    addition function () {
      $ GLOBALS [ 'z'] = $ GLOBALS [ 'x'] + $ GLOBALS [ 'and'];
    }
    Addition ();
    echo $ z;
  ?>

  2.  $ _SERVER is an array containing information such as header information (header), a path (path), and the position of the script (script locations) and the like. The array of items created by the Web server. Each server provides no guarantee that all items; servers may omit some, or provide some not listed here out of the project.

  

 

   

  Example:

  ? <PHP
    echo $ _SERVER [ 'PHP_SELF']; // filename of the currently executing script
    echo "<br>";
    echo $ _SERVER [ 'SERVER_NAME']; // host name of the server where the current script
    echo "< br> ";
    echo $ _SERVER [ 'HTTP_HOST']; // current request header Host: the content item, if any.
    echo "<br>";
    echo $ _SERVER [ 'HTTP_REFERER']; // previous page guides the user agent to the current page address.
    echo "<br>";
    echo $ _SERVER [ 'HTTP_USER_AGENT'];
    echo "<br>";
    echo $ _SERVER [ 'SCRIPT_NAME']; // contains the current script's path.
  ?>

  

 

   3. $ _ REQUEST used to collect data HTML form submission. The following example shows the form (form) an input field (input) and submit button (Submit) a. When the user submits the form data by clicking on the "Submit" button, the form data is sent to the <form> tag action attribute specified in the script file. In this example, we specify the file to process the form data. If you want other PHP files to process the data, you can modify the specified script file name. Then, we can use the super global variable $ _REQUEST to collect data input field in a form:

 Example: 

  <div class="box1">
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
      Name: <input type="text" name="liang">
      <input type="submit">
    </form>

    <?php
      $name = htmlspecialchars($_REQUEST ['liang']);
      echo $name;
    ?>
  </div>

   . 4 $ _ POST is widely used in the collection form data, specify the attribute in HTML form tag:. "Method =" post "The following example shows a form (form) an input field (input) and submit button (Submit) a. when the form is submitted data users by clicking on the "submit" button, the form data is sent to the <form> tag action attribute specified in the script file. in this example, we specify the file to process the form data. If you want other PHP file to process the data, you can modify the specified script file name. then, we can use the super global variable $ _POST data to gather input field in a form

  Example:

  <div class="box1">
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
      Name: <input type="text" name="liangA">
      <input type="submit">
    </form>

    <?php
      $name = htmlspecialchars($_POST ['liangA']);
      echo $name;
    ?>
  </div>

  5. The $ _GET  likewise been widely used in the collection form data, the attribute specified in the HTML form tag:. $ _ GET URL may be transmitted to collect "method =" get "data.

  

 

 

Guess you like

Origin www.cnblogs.com/hermit-gyqy/p/11599434.html