Jump to content

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>

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.