top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How do I unset or destroy sessions in PHP?

0 votes
446 views
How do I unset or destroy sessions in PHP?
posted Aug 15, 2013 by Meenal Mishra

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

1 Answer

+1 vote
 
Best answer

Unset will destroy a particular session variable whereas session_destroy() will destroy all the session data for that user. Now use them accordingly.

unset($_SESSION['name']); // will delete just the name data
session_destroy(); // will delete ALL data associated with that user.

Source: http://stackoverflow.com/questions/5697822/session-unset-or-session-destroy

answer Aug 15, 2013 by anonymous
Similar Questions
0 votes

I want to write online user module for my site and I want to check $_SESSION['userID'] to find all users id who loged in but when I echo this code its return only current user detail how I can see all sessions?

foreach($_SESSION as $k => $v)
{
echo $k."----------".$v;
}

or how I handle online users?

0 votes

I have the following (below) session code at the top of each page.. The 'print_r' (development feature only) confirms that on one particular page I do log out as the session var = (). but, on testing that page via the URL I still get to see the page and all its contents - session var() -.. the page has the following session_start, DOCTYPE Info then containing meta info

error_reporting (E_ALL ^ E_NOTICE);
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
print_r($_SESSION);
+2 votes

I'm having a problem getting my objects out of the $SESSION variable. I am storing an ordinal array of associate arrays where one of the associate array elements is an object. Unfortunately, when I pull it back out, the object is "broken" with "__PHP_Incomplete_Class" errors.

From what I can read this has something to do with 'serialization' - i.e., the emerging object must be unserialized (http://php.net/manual/en/function.unserialize.php ). However, I can't get it to work.

Any tips on how that is done, or what I should do instead?

This program is being developed on a testing server that can then be put on a production server.

Here are my server specs:
Apache Version : 2.2.17
PHP Version : 5.3.3
MySQL Version : 5.5.8

...