0

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");
?>
4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by R0bb0b
0

try this code:

session_start();
session_unregister('uname');
session_destroy();
header ("Location: login.php");
0

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']);
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.