Jump to content

Cookie removal frustration!


brad_lucas

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/51466-cookie-removal-frustration/
Share on other sites

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.