Jump to content

Weird, can't clear cookies


TapeGun007

Recommended Posts

Ok, so I used to have my website located on an IP address while it was in development.  Then I transferred the domain over to the new host.

 

This used to clear all the cookies no problem, now it does not.

 

If (isset($_GET["logout"]))
{	

setcookie('Active','',time()-3600);
setcookie("MemberID","",time()-3600);
setcookie("FirstName","",time()-3600);
setcookie("LastName","",time()-3600);
setcookie("Admin","",time()-3600);
setcookie("SuperAdmin","",time()-3600);
setcookie("Admin_Rights","",time()-3600);
  	// echo '<META HTTP-EQUIV="Refresh" Content="0; URL=login.php">';    
   	
echo $_COOKIE['Active']."<br>";
echo $_COOKIE['MemberID']."<br>";
echo $_COOKIE['FirstName']."<br>";
echo $_COOKIE['LastName']."<br>";
echo $_COOKIE['Admin']."<br>";
echo $_COOKIE['SuperAdmin']."<br>";
echo $_COOKIE['Admin_Rights']."<br>";
exit;
}

 

The result is that these echo statement return values of the cookies under the domain name.  However, if I go back and load this website through the IP address, they work just fine.

 

I have tried to clear out the MSIE 8 cache and such, and restarting it, but it still continues to fail, but only if I load the website via the domain. 

 

Why?

Link to comment
Share on other sites

To understand why this happens you have to understand how cookies are sent to the server. Cookies are sent to the server only in the HTTP headers at the beginning of a HTTP request. Meaning that no matter what you do to the cookies during the script you won't notice a change until the next time the updated cookies are sent back to the server, which is on the next request.

Link to comment
Share on other sites

Cookies are domain specific. If you set them using the domain, then use the ip address to access the website to see if they're being cleared it's only giving you the illusion that they're being cleared on the same request because they were never set. That's my best guess at least, I'm not entirely sure I understand your situation.

Link to comment
Share on other sites

Well... I discovered that using:

 

header('Location:login.php');

 

Works and using

 

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=login.php">';

 

does not.  For whatever reason, the META will not clear out the info and reset the cookies, but the header will.  Which I'm assuming this goes back to what you were saying earlier about how cookies actually operate.

Link to comment
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.