Jump to content

[SOLVED] What is the correct way to get rid of a session?


limitphp

Recommended Posts

I use sessions now to handle the login. 

When they click logout, it takes them to website.com?logout=yes

 

here is the code I am trying to use to log them out:

<?php
if ($logout=="yes")//***********	DESTROY SESSION, DELETE COOKIE, DELETE ENTRY
{
session_unset();
session_destroy(); 
if (isset($_COOKIE['nwo']))
{
	$queryDelete = "DELETE FROM cookie WHERE tempID = '$_COOKIE[loggedin]'";
	mysql_query($queryDelete) or die (mysql_error());
	setcookie("loggedin","out", time()-3600*24);
}
}
?>

 

It gives me a Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in C:\wamp\www\greckle\index.php

 

does anyone know what I am doing wrong?

thanks...

Something like...

 

<?php
session_start();
if ($logout=="yes")//***********   DESTROY SESSION, DELETE COOKIE, DELETE ENTRY
{
$_SESSION = array();
session_destroy();
if (isset($_COOKIE['nwo']))
{
	$queryDelete = "DELETE FROM cookie WHERE tempID = '$_COOKIE[loggedin]'";
	mysql_query($queryDelete) or die (mysql_error());
	setcookie("loggedin","out", time()-3600*24);
}
}
?>

 

But I still don't know where $logout comes from?

Something like...

 

<?php
session_start();
if ($logout=="yes")//***********   DESTROY SESSION, DELETE COOKIE, DELETE ENTRY
{
$_SESSION = array();
session_destroy();
if (isset($_COOKIE['nwo']))
{
	$queryDelete = "DELETE FROM cookie WHERE tempID = '$_COOKIE[loggedin]'";
	mysql_query($queryDelete) or die (mysql_error());
	setcookie("loggedin","out", time()-3600*24);
}
}
?>

 

But I still don't know where $logout comes from?

 

sorry...

$logout = check_input($_GET['logout']);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.