Blog Details

Sessions



                                

* PHP Sessions :-

  • A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.
  • Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID. The UID is either stored in a cookie or is propagated in the URL.

Storing a Session Variable :-

<?php session_start(); // store session data $_SESSION['views']=1; ?> <html> <body> <?php //retrieve session data echo "Pageviews=". $_SESSION['views']; ?> </body> </html>  

Output:

Pageviews=1

 Destroying a Session :-

  • If you wish to delete some session data, you can use the unset() or the session_destroy() function.
  • The unset() function is used to free the specified session variable:
<?php session_start(); if(isset($_SESSION['views'])) unset($_SESSION['views']); ?>
  • You can also completely destroy the session by calling the session_destroy() function:
<?php session_destroy(); ?>  


Categories

Core_PHP

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote