PHP provides a special set of predefined global arrays containing various useful nuggets of information. These arrays are known as superglobals because they’re accessible from anywhere in your script — including inside functions — and you don’t need to declare them as global using the
global keyword.
Here’s a full list of the superglobals available in PHP, as of version 5.3:
$GLOBALS Contains a list of all global variables in the script (excluding superglobals)$_GET Holds a list of all form fields sent by the browser using the GET request$_POST Holds a list of all form fields sent by the browser using the POST request$_COOKIE holds a list of all cookies sent by the browser$_REQUEST Contains all the keys and values in the $_GET, $_POST and $_COOKIE arrays combined$_FILES holds a list of any files uploaded by the browser$_SESSION allows you to store and retrieve persistent session variables for the current browser$_SERVER Holds server environment info such as the filename of the running script, and the IP address of the browser.$_ENV contains a list of environment variables passed to PHP. These can include variables provided by the shell, as well as CGI variables.
For example, we can use the
$_GET superglobal to retrieve a value included in the query string of the script’s URL, and display the value in the page:<?php $yourName = $_GET['yourName']; echo "Hello, $yourName!"; ?>
If you run the above script using a URL along the lines of
http://www.example.com/script.php?yourName=Fred then the script displays:
0 comments:
Post a Comment