What are different PHP Superglobal arrays and their use
What are different PHP Superglobal arrays and their use?
When information is passed from one web page to other web page or some other script, it has to be stored on some global variable which can be accessed regardless of scope of script.
There are different superglobals and their use.
$GLOBALS superglobal array allow you to access global variable .All variables in the global scope are loaded into the $GLOBALS array, allow you to access them using the variable name as the array key.
The $_SERVER superglobal stores information about the server and the current script. It also has features that allow you to access the IP address of a site visitor .One of the most useful pieces of information available in the $_SERVER superglobal is the name of the host site, which is stored in HTTP_HOST
This array is used to collect data send from HTTP get method. One of the two most common methods of passing data between pages is the GET method. GET data is passed through a query string in the URL, which appears in browser address bar ,looks something like this:
This array is used to collect data send from HTTP post method. PHP provides a second method for sending data POST. Structurally, POST requests are very similar to GET requests, and you access their values in the same way. Unlike GET, data will not be appeared in the address bar of browser after submitting data.
This array is used to collect all data send from HTTP form.The $_REQUEST superglobal is an array that contains the contents of the $_GET, $_POST, and $_COOKIE superglobals.
This array is used to collect data passed by an HTML file input. In an application such as the job portals, where you uploads CV and images. In order to access an uploaded
file, you need to use the $_FILES superglobal. $_FILES works a little differently from $_POST and $_GET in that each file creates an array of related elements that provide information about the uploaded file. The provided information
·name: The file name
·type: The file type
·tmp_name: The temporary location of the uploaded file
·error: An error code corresponding to error type (0 if no errors found)
·size: The file size in bytes
This array is used to maintained current session data specific to the user, the $_SESSION superglobal provides a practical, easy solutionOne common use of $_SESSION variables is to store a user’s login status.
Cookies behave similarly to sessions, but they allow you to store information on a user’s machine for a longer period of time. Information stored in cookies remains available even after the user closes her browser.
In PHP, you use the $_COOKIE superglobal to access cookie values.
echo " <h2 > " ;
echo " To demonstrate SuperGlobals in PHP <br > < br > " ;