The PHP Predefined Superglobal Variables
Superglobal variables are
automatically created and initialized by the PHP engine, and are
accessible throughout the script. We’ve already seen the $_GET
and $_POST
associative arrays that contain data
passed to the script from a form using the GET
or POST
method, respectively.
The array $_SESSION
contains data related to a user’s
interaction with a web application within a single session; we
describe sessions and this variable in Sessions,” later in this chapter.
The $_COOKIE
array contains cookie data provided
by the user’s browser. Cookies are strings that
are passed back and forth between the web server and browser to
maintain a unique key. They are useful for storing information on a
user on the user’s computer; you can use the PHP set_cookie()
function to send a cookie to the user’s browser. Each subsequent time the user visits your site, his browser automatically provides the cookie data. Cookies can be set to expire once the user closes their browser, at a later date, or never. A good use for cookies is to remember what news articles users have read and to show them new articles that they haven’t read yet. Note that cookies should never be used to store confidential information, as they are not secure. In addition, they shouldn’t be used to store information critical to your application, since users can move among computers, or modify or delete cookies at any time. Cookies have been widely abused by companies trying to track user web ...
Get Learning MySQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.