Session¶
Session support in PHP consists of a way to preserve certain data across subsequent accesses to the web server.
By default, each query to a webserver is independent from the others. With session, it is possible to keep some data on the server, and retrieve them at each access.
It relies on the session_* functions, and the $_SESSION superglobal variable.
<?php
if (isset($_SESSION['x'])) {
print 'x was already set with the value ' . $_SESSION['x'];
}
$_SESSION['x'] = rand(0, 10);
print 'Giving the value ' . $_SESSION['x'] . 'to x, in the session';
?>
See also Session in PHP: Creating, Destroying, and Working With Session in PHP, Sessions security and Fixing PHP Session Issues: Troubleshooting and Solutions.
Related : Superglobal Variables, Object Persistence, Persistence, Session Fixation, Session Hijacking, Horizontal Scaling, Race Condition, Single Sign On (SSO), State, JSON Web Token (JWT), Load Balancer, SessionHandlerInterface, SessionIdInterface, SessionUpdateTimestampHandlerInterface