Skip to content
Home » Web » PHP » How to Distinguish the Scope of Superglobals in PHP

How to Distinguish the Scope of Superglobals in PHP

The superglobals in PHP are:

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

Don't be confused by the name of superglobals, their scopes vary from one to another:

  • $GLOBALS
  • The scope can be across scripts including functions and methods, but it must be within the same web page.

  • $_SERVER
  • The scope is the same as $GLOBALS.

  • $_GET
  • The scope is the same as $GLOBALS.

  • $_POST
  • The scope is the same as $GLOBALS.

  • $_FILES
  • The scope is the same as $_POST.

  • $_COOKIE
  • The scope can be across pages, sessions, instances until expired, but it must be within the same browser.

  • $_SESSION
  • The scope can be across pages, but it must be within the same session.

  • $_ENV
  • The scope can be across pages, sessions, and instances, but it must be within the same shell.

Leave a Reply

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