Articles → PHP → Sessions in PHP

Sessions in PHP











<?php
// this is compulsory statement if you want to access session variable in the page. This indicates that we are going to access session variables in this page
session_start();
// store session data
$_SESSION[‘userid’] = 1;
//retrieve session data
echo "Userid=" . $_SESSION[userid];
session_destroy(); // will reset your session and you will lose all your stored session data.

?>
This very basic use of session say now you want to change the value of session and want to check if the session exits.
<?php
session_start();
if (isset($_SESSION['views'])) $_SESSION['views'] = $_SESSION['views'] + 1;
else $_SESSION['views'] = 1;
echo "Views=" . $_SESSION['views'];
?>



Posted By  -  Geetanjali
 
Posted On  -  Friday, January 15, 2016

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250