Session Management Functions in php
session_start()
Initialize session data
Syntax : bool session_start ( void )
session_start() creates a session or resumes the current one based on the current session id that’s being passed via a request, such as GET, POST, or a cookie.
If you want to use a named session, you must call session_name() before calling session_start().
session_start() will register internal output handler for URL rewriting when trans-sid is enabled. If a user uses ob_gzhandler or like with ob_start(), the order of output handler is important for proper output. For example, user must register ob_gzhandler before session start.
Parameters :
None
Return Values :
This function always returns TRUE.
Examples :
<?php
session_start();
if(isset($_SESSION['views']))
$_SESSION['views'] = $_SESSION['views']+ 1;
else
$_SESSION['views'] = 1;
echo "views = ". $_SESSION['views'];
?>
DISPLAY : views = 1
Cleaning and Destroying your Session
PHP Code:
<?php
session_start();
if(isset($_SESSION['cart']))
unset($_SESSION['cart']);
?>
You can also completely destroy the session entirely by calling the session_destroy function.
<?php session_start(); session_destroy(); ?>




