Sessions in PHP
Full code - session.php
<?php
session_start();
function makeSession($name, $value)
{
$_SESSION[$name] = $value;
}
function checkSession($name, $value)
{
…Tutorial
NB: When you use sessions the code session_start(); must be put at the start of every page.
To create a session in PHP you simply assign a (key, value) pair to the $_SESSION array.
$_SESSION[$name] = $value;
To read a value from a session you use the $_SESSION array.
if ($_SESSION[$name] == $value)
echo 'You are logged in.';
else
echo 'You are not logged in.';
This example checks to see if a session has a certain value and prints a message depending on whether the session has the correct value.
setcookie($name, '', time()-100000);
unset($_SESSION[$name]);
session_destroy();
To delete a session you firstly need to delete the associated cookie (the cookie has the same name as the session) and then delete the entry in the array.
session_unset();
The code above deletes all sessions that are active.
Adobe Fireworks® Adobe Flash® and Adobe Photoshop® are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries.
MySQL is a registered trademark of MySQL AB in the United States, the European Union and other countries.
MySQL is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Copyright Pixelcode 2005 - 2010