Session saves the users data in secured manner compare with cookies.
session_start()
function and $_SESSION
is superglobals variable.Similar to the cookies start session before <html>
tag.
Syntax:
[php]
<!DOCTYPE html>
<?php session_start(); ?>
<html>
<body>
<?php //Session Variables data that were set on previous page
echo "Name : " . $_SESSION["name"] . ". ";
echo "Mobile : " . $_SESSION["mobile"] . ".";
?>
</body>
</html>
[/php]
session_unset()
and session_destroy()
.
[php]
<!DOCTYPE html>
<?php session_start(); ?>
<html>
<body>
<?php
session_unset(); // removes all session variables
session_destroy(); // destroy the session
?>
</body>
</html>[/php]