markkanning Posted February 7, 2007 Share Posted February 7, 2007 Hey folks, I'm having trouble with a cookie setting/deleting function in one of my scripts for logging in and out of a website CMS. In testing it, I've found that if I login once, then logout, the 2 cookies in question(one being set at the point of login and another being set by a session that MySQL querries are being fed from) will successfully be deleted as intended. However, a second login and logout will NOT delete the same cookies. Is there something else I'm not considering, something else being cached that could be causing this? Here's the cookie setting/deleting code: if (isset($_REQUEST[uid]) AND !isset($_COOKIE[cookieid])) { $grabuser = "SELECT recID FROM user WHERE username = '$_REQUEST[uid]' AND password = '$_REQUEST[pwd]'"; $result = @mysql_query($grabuser); sql_query($result, "$errors[03]"); if (@mysql_num_rows($result) == 0) { include ($_SERVER['DOCUMENT_ROOT'].'/layout.php'); adminHeader(); warningSecureArea(); adminBoxSecurity(); error ("$errors[04]"); include ($_SERVER['DOCUMENT_ROOT'].'/login_form.php'); adminFooter(); exit(); } //If username/password match, set cookie to the value "$userid" and name it "cookieid" else { $userid = @mysql_result($result,0,"recID"); $processing_login = true; $cookie_setter = setcookie ("cookieid", $userid, time()+$maxlifetime); } } //Delete "cookieid" and "PHPSESSID" on logout if ($_REQUEST[action] == "logout") { setcookie ("cookieid", "", time()-$maxlifetime); setcookie ("PHPSESSID", "", time()-$maxlifetime); include ($_SERVER['DOCUMENT_ROOT'].'/layout.php'); adminHeaderRefresh(); echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" align=\"center\" style=\"width:38px;margin:50px auto 0 auto;\"><tr><td><img src=\"/images/lockiconfilling.gif\"></td></tr></table>"; adminBoxSecurity(); echo "<center><h1>LOGGING OUT...</h1><br>If this page does not refresh in 3 seconds, <a href=\"/admin.php\">click here</a>.</center>"; adminFooter(); exit(); } Anyone got any ideas as to what I could add to make sure a second logout would be successful? Mark Link to comment https://forums.phpfreaks.com/topic/37494-cookie-deleting-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.