Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.