Login

Username:

Password: 

Join us Now |  Forgot Password? | Forgot UserName?

PHP

Learn step by step



PHP Session

A session is the time a user spends at a website encompassing everything they do in that time at the website. PHP allows for what is called a session variable - a variable that is used to store information about, or change settings for a users session. A session variable can hold information about a single user, and is available to all pages within the same domain.

Start a session
<?php
session_start();
?>
<html>
<body>
</body>
</html>
Storing and using session variables
<?php
session_start();
// store session data
$_SESSION['views']=1;
?>

<html>
<body>

<?php
//retrieve session data
echo "Pageviews=". $_SESSION['views'];
?>

</body>
</html>
Destroying a Session
<?php
// you have to open the session to be able to modify or remove it
session_start();

// to change a variable, just overwrite it
$_SESSION['size']='large';

//you can remove a single variable in the session
unset($_SESSION['shape']);

// or this would remove all the variables in the session, but not the session itself
session_unset();

// this would destroy the session variables
session_destroy();
?>


Related Videos