2. COOKIES
Like variable
Stores single piece of data
under a unique name
Browser dependent
stores cookies on user‟s browser
Moves page to page
Avoids the problem to log in every time
Always stored as text
3. COOKIES WITH PHP
Set cookie
setcookie() stores data in cookies
Syntax: setcookie(“cookie name”,”value”);
Accepts an optional third argument
E.g: setcookie(„username‟, „aacssh‟, time()+(60 * 60));
Sets the expiration date of the cookie
Sets expiration date 1 hour (60sec * 60min) from the current
time
Retrieve cookie
using super global using $_COOKIE
E.g:
$_COOKIE[„cookie name‟];
5. SESSION
Time spend by user at web application
Stores small piece of data on server
More secure and more reliable
Automatically destroyed by shutting down the
browser
Stored in session variable
6. SESSION WITH PHP
Starting session
Started by function session_start()
Allow data to store in session variables
Should be the first line of code
End session
Close session with session_destroy()
7. (CONT…)
Session variables
Set session variable with super global $_SESSION
Once created , gets stored on the server
E.g: $_SESSION[„variable‟] = value;
Variable = name of session
Delete session variables manually
Not
automatically deleted when session is destroyed
Set $_SESSION superglobal to an empty array
E.g: $_SESSION = array();
9. USING BOTH SESSION AND COOKIE
Sessions have short life
Cookie can last forever
Long enough to outlast a session
If session uses cookie to remember session id
Cookie id is name after the session
i.e session_name()
To close session, cookie must also be deleted