PHP Predefined Variables

please click here for more wordpress cource

PHP has a number of predefined variables that are available in all scopes throughout a script. These variables are automatically populated by the PHP engine with information relevant to the script’s execution. Here are some of the most commonly used predefined variables in PHP:

  1. $_SERVER: This variable contains an array of information about the server and the script’s execution environment, such as the script’s filename, the server’s IP address, and the request method used to access the script.
  2. $_GET: This variable contains an associative array of variables passed to the script through the URL’s query string. For example, if the URL is http://example.com?name=John&age=25, the $_GET array would contain ['name' => 'John', 'age' => '25'].
  3. $_POST: This variable contains an associative array of variables passed to the script through an HTTP POST request. For example, if a form with fields name and age is submitted to the script, the $_POST array would contain ['name' => 'John', 'age' => '25'].
  4. $_SESSION: This variable contains an associative array of variables that are persisted across multiple requests from the same client. This is commonly used to store user-specific data such as login information.
  5. $_COOKIE: This variable contains an associative array of variables passed to the script through HTTP cookies. Cookies are commonly used to store user-specific data such as preferences or session IDs.
  6. $_FILES: This variable contains an associative array of uploaded files passed to the script through an HTTP POST request. This is commonly used when allowing users to upload files to a website.
  7. $GLOBALS: This variable is a superglobal that contains all variables defined in the global scope of the script.

By using these predefined variables, PHP developers can easily access and manipulate data that is relevant to the script’s execution.

You may also like...

Popular Posts

Leave a Reply

Your email address will not be published. Required fields are marked *