PHP- session Example

Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.

A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.

Session Example in PHP:

Source : session_start

// Initialize the session.
//store values
$_SESSION[‘favcolor’] = ‘green’;
$_SESSION[‘animal’] = ‘cat’;
$_SESSION[‘time’] = time();

//print stored values

echo $_SESSION[‘favcolor’]; // green
echo $_SESSION[‘animal’]; // cat
echo date(‘Y m d H:i:s’, $_SESSION[‘time’]);

// Unset all of the session variables.
$_SESSION = array();

// Finally, destroy the session.

Related Posts: