Superglobals in PHP With Examples
Superglobals in PHP With Examples
Superglobals in PHP With Examples
[2 Steps]
Here is simple example where I have submit form which is point to itself for
process with data with POST method. Now in PHP script I am using the super
global variable $_REQUEST to get the value of the input field.
Output:
4. $_POST Variable in PHP:
In this PHP $_POST is a PHP super global variable which is used to collect form
data after submitting an HTML form with method=”POST”.$_POST is also widely
used to pass variables.
In the above code we have created a form that takes name and age of the user
and accesses the data using $_POST super global variable when they submit
the data. Since each superglobal variable is an array it can store more than one
values. Hence we retrieved name and age from the $_POST variable and stored
them in $nm and $age variables.
Conclusion:
In this article we are going to cover Superglobals in PHP with Examples, List of
Superglobal variables in PHP.
6. $_FILES
Description ¶
An associative array of items uploaded to the current script via the HTTP POST
method. The structure of this array is outlined in the POST method uploads section.
The global $_FILES will contain all the uploaded file information. Its contents from
the example form is as follows. Note that this assumes the use of the file upload
name userfile, as used in the example script above. This can be any name.
$_FILES['userfile']['name']
$_FILES['userfile']['type']
The mime type of the file, if the browser provided this information. An example
would be "image/gif". This mime type is however not checked on the PHP side
and therefore don't take its value for granted.
$_FILES['userfile']['size']
$_FILES['userfile']['tmp_name']
The temporary filename of the file in which the uploaded file was stored on
the server.
$_FILES['userfile']['error']
$_FILES['userfile']['full_path']
The full path as submitted by the browser. This value does not always contain
a real directory structure, and cannot be trusted.
7. $_ENV
$_ENV — Environment variables
Description ¶
An associative array of variables passed to the current script via the environment
method.
These variables are imported into PHP's global namespace from the environment
under which the PHP parser is running. Many are provided by the shell under which
PHP is running and different systems are likely running different kinds of shells, a
definitive list is impossible. Please see your shell's documentation for a list of
defined environment variables.
Other environment variables include the CGI variables, placed there regardless of
whether PHP is running as a server module or CGI processor.
8. $_COOKIE
$_COOKIE — HTTP Cookies
Description ¶
An associative array of variables passed to the current script via HTTP Cookies.
Examples ¶
<?php
echo 'Hello ' . htmlspecialchars($_COOKIE["name"]) . '!';
?>
9. $_SESSION
$_SESSION — Session variables
Description ¶
An associative array containing session variables available to the current script. See
the Session functions documentation for more information on how this is used.
Session Functions ¶
Table of Contents ¶