Sunday, 9 June 2013

How to delete a session variable in php?

Before I tell you how to delete the session variable, Let me explain the use of session.

Sessions are used in web applications to store the information about the user on the server. So once you create the session variables, you can access those variables from all pages in the applications. Without sessions, it is not possible to access information from one page to another.

So How to create sessions and session variables?

<?php

session_start();   //function to start the session

$_SESSION['uid']=12323;  // store user id in session variable

?>
Now $_SESSION is a global variable and you can use it from any page of the application.



How to delete the session variable in PHP?

<?php
if(isset($_SESSION['uid']))   //check if session variable exists
  unset($_SESSION['
uid']);   // if exists, delete that session variable

?>


How to delete All session variables in PHP at one go?

<?php
Session_Destroy();

?>


No comments:

Post a Comment