brad_lucas Posted May 15, 2007 Share Posted May 15, 2007 Hey guys, I am having a really hard time removing cookies and I can't for the life of me figure out what is going on. Here's a snippet: //This is a global function stored in an included file. function setmycookies($switch) { global $userID,$username,$encryptedpass; if($switch == "1"){ setcookie('cookie1',$encryptedpass,time()+3600); setcookie('cookie2',$userID,time()+3600); setcookie('cookie3',$username, time()+3600); }else{ setcookie('cookie1','',time()-3600); setcookie('cookie2','',time()-3600); setcookie('cookie3','', time()-3600); } } Then on my "login" page, I verify the user etc and then set the cookies thusly: setmycookies("1"); When they're ready to logout, I clean up my cookies: setmycookies("0"); Seems pretty sound right? Except it doesn't exactly work...You see, the cookies DO get set with setmycookies("1"), but they will NOT expire with setmycookies("0"). To add confusion to the issue, I've gone so far as to set another cookie on logout (eg: setcookie("blah", "blah", time()+360)) and then refresh the logout page...viola, there's the new cookie. I jump back into my code and reverse it (eg: setcookie("blah", "", time()-3600)) and BINGO! It deletes! So why the heck wont the other three? Any ideas, suggestions? I'm nearing the end of my tether and am almost positive I'm going mad! Please help. Brad Quote Link to comment https://forums.phpfreaks.com/topic/51466-cookie-removal-frustration/ Share on other sites More sharing options...
clown[NOR] Posted May 15, 2007 Share Posted May 15, 2007 just out of curiosity ,... have you tried elseif ($switch == "0") { //delete cookies } ?? Quote Link to comment https://forums.phpfreaks.com/topic/51466-cookie-removal-frustration/#findComment-253505 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.