Page 1 of 1

[SOLVED] session_destroy

Posted: Fri Jan 27, 2006 11:46 am
by $var
if you have a session based on a cookie.. so like:

Code: Select all

$id = $_COOKIE['ID01'];	
	if ($_SESSION['IDO1'] != $id) {
	header("Location: index.php");
	}
how do i make a text link, not a button to log out, or destroy the session?

Posted: Fri Jan 27, 2006 12:03 pm
by shiznatix
im not sure what you are saying. do you want to destory the session with a link? if so just make a link to logout.php and make logout.php look like this

Code: Select all

session_start();
$_SESSION = array();
session_destroy();
header("Location: index.php");
die();

Posted: Fri Jan 27, 2006 12:16 pm
by $var
yah, okay... that'd be fine... i was just wondering if you could do it without having the go to another page.

Posted: Fri Jan 27, 2006 12:30 pm
by feyd
Just a word of warning, the cookie may not be destroyed on some browsers when hitting a header() redirected page..

Posted: Fri Jan 27, 2006 12:40 pm
by $var
hmm... but if i clear the session on the index.php, would that work, if it didn't clear the first time with the header, it should the second right?

Posted: Fri Jan 27, 2006 12:42 pm
by feyd
the session data will be cleared, I'm simply saying the session id cookie may not. Which can be perfectly fine if you no longer have hooks related to that id anywhere.