There are various predefine “superglobals” in PHP. These variables can easily accessible in function or class.

Following are the superglobals variables:

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GETetc.

PHP $GLOBALS

The “$GLOBAL” isa keyword that is used to accesssuper global variablefrom anywhere in the PHP script.

Example 1:

Output

50

PHP $_SERVER

PHP  $_SERVER is a PHP super global variable that holds the information about headers, paths, and script locations.

Example 2:

Output

/crud/hello.php

localhost

localhost

Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36

/crud/hello.php

Superglobals variables are given below:

Element/Code Description
$_SERVER[‘PHP_SELF’] Returns the filename of the currently executing script
$_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[‘HTTPS’] Is the script queried through a secure HTTP protocol
$_SERVER[‘SCRIPT_URI’] Returns the URI of the current page

PHP $_REQUEST

PHP $_REQUEST is used to gather data after submitting html form.

Example:

PHP $_POST

PHP $_POST is used to collect data after submitting the form using$_post”method. It is also used to pass the variables.

Example

Pin It on Pinterest

Share This