Академический Документы
Профессиональный Документы
Культура Документы
A session is a way to store information (in variables) to be used across multiple pages.
How Session Works
Store a Cookie on Client Machine
Session
session_start( ) If NO Cookie_Name – PHPSESSID
available ? Content – SessionID
If Yes
Store a file on Server
Name – SESS_SessionID
Content – Session_Variable
It matches PHPSESSID Cookie’s
Session ID with Server’s File
Session ID: 80ibbfgbh7cl6lakgg87dlhv7v
If both match
Note: The session_start() function must be the very first thing in your document. before any
HTML tags.
Set Session Variables
Session variables are set with the PHP global variable $_SESSION. These
variables can be accessed during lifetime of a session.
$_SESSION[‘username’] = ‘geekyshows’;
$_SESSION[‘password’] = ‘geek’;
$_SESSION[‘time’] = time();
$_SESSION[‘cart’] = $number;
Get/Access Session Variables
Session variables are stored in the PHP global variable $_SESSION.
$_SESSION[‘username’];
$_SESSION[‘password’];
$_SESSION[‘time’];
$_SESSION[‘cart’];
Unset Session Variable
• unset($_SESSION[‘varName’]) – This is used to
free/unset/unregister a session variable.
Ex:- unset($_SESSION[‘username’])