Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Destroy Problem

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Hi,

I am using the following code to log a user out of my site
and return them to the home page etc, but it doesn't seem to work as some kind phpsessionid is carried forward which disrupts a search function I have on my homepage. Can anyone see anything I am doing incorrectly.

Tks

********************* Code *********************888

if (mysql_affected_rows() ==1)
{

$_SESSION = array();
// Destroy the session itself
session_destroy();
// destroy the cookie
setcookie (session_name(), '' , time()-300, '/' , '',0);
header ("Location: . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/thank_you.php");
}
 
not 100% certain here but i'd guess you should unset the cookie before you unset the session variables or destroy the session (otherwise how does it know the session name?).

i'd suggest also using session_unset() before session_destroy() (although your $_SESSION=array() does the same thing).

remember also to use session_start before unsetting or destroying.

for the cookie itself, the notes to the php manual suggest;
Code:
setcookie( session_name() ,"",0,"/");
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top