Session
What is Session?

Session is way to store information and this information will be available to all pages in one application. But when close browser the session information will destroy.

How to create session?

For maintaing session firstly call session_start() function. Because session_start() start session. Then create session variable like

$_SESSION['username']='shishir012010';

here $_SESSION['username'] is a session variable and shishir012010 is information that store in $_SESSION['username'] variable.

 

Example 1:- To create session

<?php
session_start();
$_SESSION['username']='shishir012010';
?>

Example 2:- To access session

<?php
session_start();
echo $_SESSION['username'];
?>

Example 3:- To delete session

<?php
session_start();
unset($_SESSION['username']);
?>

Note:- The unset function is use delete one session variable.

Example 4:- To delete all session variable

<?php
session_start();
session_destroy();
?>

Note:- session_destroy() function delete all session variable.

Session_id()

session_id() function returns the session id for the current session.

Example 6:-

<?php
session_start();
echo session_id();
?>

Note:- we use session_id() for maintaining shopping cart.


Previous
Next