Jump to content

[SOLVED] Problems deleting my cookies


almightyegg

Recommended Posts

My cookies were made to last 3600*24 , do I have to delete them with the same time?

 

No, if you are logging out then you want to destroy the cookie. To destroy the cookie you need to set it's time the past and also give it an empty value.

 

setcookie ("my_cookie", "Logged_in", time()+3600); 

//the cooikie 'my_cookie' will last for 3600 seconds, or one hour from the current time.

 

and

 

setcookie ("cookie", "", time()-3600); 

//will delete the cookie

 

 

this is my code

<?
setcookie("email", "", time() - 3600);
setcookie("password", "", time() - 3600);
$email = $_COOKIE['email']; 
$password = $_COOKIE['password']; 
?>
<html>
<title>Logout</title><link rel="stylesheet" href="default.css">
<body bgcolor="black">
Thanks for playing. Please come back soon.
<?
echo "$email, $password";
?>
</body>
</html>

 

I can't spot any reasons why it's not deleting

Now I'm really confused! I tried it, making it called yippie, destroyed it, echoed it and it echoed my email address that I logged in with..... wth?

 

 

But the name of the cookie is 'email'.....it's value is 'yipee'. If you echo 'email' you should get 'yipee' returned.....

 


setcookie("email", "yipee", time()+3600);

echo $_COOKIE["email"];  // returns 'yipee'

 

Delete all your browsers cookies so we can start fresh. Create the cookie named 'email' and give it a value of 'yipee'. Echo out the cookie and you should get 'yipee' on the page.

 

Next, delete the cookie and echo it out and you should get nothing...

 


setcookie("email", "", time()-3600);

echo $_COOKIE["email"];  // returns nothing at all

<?
setcookie("email", "", time() - 3600);
setcookie("password", "", time() - 3600);

?>
<html>
<title>Logout</title><link rel="stylesheet" href="default.css">
<body bgcolor="black">
Thanks for playing. Please come back soon.
<?
$email = $_COOKIE['email']; 
$password = $_COOKIE['password']; 
echo "$email, $password";
?>
</body>
</html>

 

That's what I have put yet still it echoes it all out still....

Hmmmm....when I run your exact code I watch the cookie vanish. But, as you say, the value still appears when I echo it out....BUT...when I refresh then the echoed valuesa aren't there anymore....because the cooi isn't there either!!

 

What about this....

 

1. Delete your cookies and redirect

 


<?php

setcookie("email", "", time() - 3600);
setcookie("password", "", time() - 3600);
Header("Location: test.php");

?>

 

2.  On test.php, echo the value of the cookies

 


<html>
<title>Logout</title><link rel="stylesheet" href="default.css">
<body bgcolor="black">
Thanks for playing. Please come back soon.
<?php
$email = $_COOKIE['email']; 
$password = $_COOKIE['password']; 
echo "$email, $password";
?>
</body>

</html>

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.