Caaaaa
Caaaaa

Reputation: 3

cookie can't expire after 10 seconds

I have created a cookie and want it to expire after 10seconds. However, it doesn't work. I have tried to close the browser but the data still here.

This is the code I set for the cookie.

setcookie('attempt','', time()+10);

Upvotes: 0

Views: 320

Answers (1)

messerbill
messerbill

Reputation: 5639

We have no idea where and how your setcookie() method is called, but it is server side in each case. So when you reload the site after closing the browser, the script is executed again and so the cookie is also sent again.

http://php.net/setcookie

You can also set cookies on the client side (which i'd prefer):

https://www.w3schools.com/js/js_cookies.asp

Upvotes: 2

Related Questions