954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

session destroy problem

hi
when i click the previous page button it was gng to logout page the sesion was not destroying when iwas using this code please help me

<?php
session_start();
session_unset($_SESSION['uname']);
session_destroy();
header ("Location: login.php");
?>
prashanth18
Newbie Poster
15 posts since Jul 2008
Reputation Points: 8
Solved Threads: 1
 

try this code:

session_start();
session_unregister('uname');
session_destroy();
header ("Location: login.php");
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

all you need to do to destroy a session is call

session_destroy();


you don't need to unset variables before then.

session_unregister is depreciated anyway.

if you want to remove something like the uname part of the session array just use

unset($_SESSION['uname']);
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

I've always just done

function destroy_sess($sessname = "all sessions")
{
	if($sessname == "all sessions")
	{
		$_SESSION = array();
	}
	else
	{
		$_SESSION[$sessname] = NULL;
		unset($_SESSION[$sessname]);
	}
}

and that works fine for everything that I do.

BTW: session_unregister() is not forward compatible with php6

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You