...

View Full Version : session isnt getting destroyed



Philly100000
04-14-2012, 09:52 AM
$errorMsg = "";
session_start();
setcookie("id", '', time()-3600*24*730, "/");
setcookie("idx", '', time()-3600*24*730, "/");
setcookie("username", '', time()-3600*24*730, "/");
setcookie("useremail", '', time()-3600*24*730, "/");
setcookie("userpass", '', time()-3600*24*730, "/");
setcookie("accounttype", '', time()-3600*24*730, "/");
session_destroy();
sleep(3);
if(!isset($_SESSION['id'])){
header("location: index.php");
exit();
} else {
$errorMsg = "Logout Error";
}


When I try to logout it doesn't let me, it removes the cookies, the but session_destroy doesnt seem to get destroyed and I'm still logged in. The Logout Error message is displaying.

fredrikrob
04-14-2012, 02:30 PM
Hi,

I am not an expert in php but i am learning php for last 4 months and have practiced many times on session's and cookies. As i have gone through your code i have seen that you are not creating session variable but instead your are creating cookies which cannot be deleted by session_destroy() method. As of this code you don't have any session variable so the condition is not getting satisfied and you are getting Logout error message.

Instead of setcookies() you must use $_SESSION["id"]=$anyvariable; to get it worked. Hope it will help you. And no doubt i might be wrong but i am sure that i am not.

tangoforce
04-14-2012, 07:29 PM
Try using unset():



unset($_SESSION);
session_destroy();

Philly100000
04-14-2012, 09:32 PM
Try using unset():



unset($_SESSION);
session_destroy();


The unset before the session_destroy fixed the problem, many thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum