top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can we destroy a session in PHP?

+2 votes
310 views
How can we destroy a session in PHP?
posted May 29, 2014 by Karamjeet Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Though PHP automatically destroys a session after timeout or user has left the website. You may need to destroy certain variables, which purpose has been accomplished or a session completely in explicit way.

Syntax of destroying session variables

<?php

session_start(); 

if(isset($_SESSION[‘UserID’]))
    unset($_SESSION['UserID']);

if(isset($_SESSION[‘name’])) 
    unset($_SESSION['name']);

?>
answer May 29, 2014 by Vrije Mani Upadhyay
+1 vote
session_destroy();
unset($_SESSION[""]);

These are the two functions which are used to destroy sessions in PHP.

answer May 30, 2014 by Mohit Sharma
Similar Questions
+2 votes

Is there a way I can clear my session data from the browser? This is for debugging when I change something. Currently no matter what I do short of exiting the browser, my session data is always retained. This makes testing very cumbersome. I am using PHP/MySQL for development.

+5 votes

I Know that we can always fetch from one database server and rewrite it to another. But what is the simplest way to do this?

...