0

How to delete cookies from the browser? Only problem, I need it to be done from server-side. With that I meant: When user opens page, server automatically deletes cookies that are related to its page. Is that possible? I need it because sometimes users are too, lets say, lazy to do it by themselfs.

daGrevis
  • 21,014
  • 37
  • 100
  • 139

3 Answers3

1

Well, there sure is a way:

if (isset($_COOKIE['cookie']))
{
    //set the expiration date an hour ago
    setcookie ('cookie', '', time() - 3600);
}

But then, you have to remember the state, that you already have deleted the cookies for that user and that session, otherwise it will be a headache to set new cookies ;)

EDIT: And this also may be useful in your case: How to delete all cookies in PHP?

Community
  • 1
  • 1
Quasdunk
  • 14,944
  • 3
  • 36
  • 45
0

set the cookie expiration value to a negative value, via your server-side scripting language

for php:

setcookie('cookie_name','',-1);

Packet Tracer
  • 3,884
  • 4
  • 26
  • 36
0
setcookie("Cookie Name","",time()-3600*24,"/");
Dzoki
  • 739
  • 4
  • 14