Coding Villa

Remove or delete session data in PHP

Author : nida khawar

Share with Friends
Views : 468
Ratings : 0
Bookmarks : 0
Farourities : 0

Description


In this simple article you will learn that how we remove or delete session data in php.


Advertisements


 

 

Session:

 

Session is used to save user data and when we close browser saved data is deleted. Session save the information about single user and that information is available on all pages in application. s

 

Session in php:

 

When we are running application on a PC our system knows who we are and when we start working and when we end but on internet no one knows. Therefore, to find out that information, we use sessions. Sessions are used to store data temporarily. We make a unique id variable for each user and store user data on that variable.

 

Syntax:

 

         Session_start ();   // for starting a session

         Session_end ();   // for ending a session

 

Remove or delete a Session in php:

 

To remove or delete a session in php we use the unset () or the session_destroy () built in function in php. Session_destroy function completely deletes or removes a session. And unset () function is also use to unset a session in php.

 

Code:

 

<?php

$_SESSION['foo'] = 'bar';

    print $_SESSION['foo'];

    unset($_SESSION['foo']);

?>

 

Above is a simple code to illustrate the basic use of unset () function to remove a session in php.

 

Code:

 

<?php

session_start();

 session_destroy();

?>

 

Above simple code uses session_destroy () function to remove a session in php.

 

This simple article tells that how we can remove or delete a session in php.

 



Article Tags
Share with Friends

Comments




Leave a Reply

Name (required)  
Mail (will not be published) (required)   
 
Enter This Code
Captcha
 

Advertisements

Article Categories

.NET


Databases


Mobile Development


Operating Systems


Web Development


Coding Villa on Facebook