[SOLVED] session_destroy

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

[SOLVED] session_destroy

Post 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?
Last edited by $var on Fri Jan 27, 2006 12:49 pm, edited 1 time in total.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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();
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

yah, okay... that'd be fine... i was just wondering if you could do it without having the go to another page.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Just a word of warning, the cookie may not be destroyed on some browsers when hitting a header() redirected page..
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply