Super Global Variables in PHP in detail ?


Super Global Variables in PHP

Definition -: Several Predefined variables in PHP are called superglobals variables which means that they are always accessible in every scope in PHP.


List of Super globals variables are -:

  • $GLOBALS
  • $_FILES
  • $_SERVER

1. $GLOBALS -: Is used to use global variables.

2. $_SESSION -: It is used to store the temporary data in a client machine for differentiating particular users.

In other words -: Session is used for login and logout purpose in which we set session if user login and session unset or destroy when user logout.

3. $_COOKIE -: It is used for cookies.

Cookies -: It is used to store the user-specific information in the form of a text file on a client machine.

In other words -: Cookies is used for tracking purpose.

4. $_REQUEST -: It is used to fetch or receive the submitted or send data using get or post method.

 5. $_GET -: It is used to fetch or receive the submitted or send data using only get method.

6. $_POST -: It is used to fetch or receive the submitted or send data using only the post method.

7. $_FILES -:  It is used to fetch or receive the submitted or send files like images.

8. $_SERVER -: It holds the host information.
In other words -: It is used to take the IP address or browser information of the user.

$_SERVER Examples -: 

  • $_SERVER["HTTP_HOST"] = Return the host header from the current request.
  • $_SERVER["HTTP_USER_AGENT"] = Return the information of client or user's browser information
  • $_SERVER["PHP_SELF"] = Return the file name with path(Inside project path) of current executing script.
  • $_SERVER["REMOTE_ADDR"] = Return the user IP address from where the user viewing the current page. 
  • $_SERVER["SERVER_NAME" = Return the name of the host server.
  • $_SERVER["SERVER_ADDR"] = Return the host server IP address.

I hope you can understand easily if you can understand easily then follow and subscribe to my blogs and share them. Otherwise, you don't follow and subscribe to my blogs.



1 comment: