How to Expire Cookies?

Asked

Viewed 372 times

0

Eae you guys, It is as follows I have created a login system that uses cookie to remember the password of the user until then everything well works normal, the problem is time to inspire these cookies, on my site’s dashboard has a quit button which is nothing more than a small form that when clicked sends via post a request to the same page of which has a condition saying if the post method comes out then expire the user cookie and password, that this the problem the cookies do not expire in no way I have tried all possible methods I found on the internet as these.

setcookie("usuario"," ",time()-10);
setcookie("usuario","",time()-10);
setcookie("usuario",NULL);
setcookie("usuario");

None of these methods worked anyone would know if you need anything else ?

  • should work

  • And how you created this cookie?

1 answer

0

I think this will solve the problem:

if (isset($_COOKIE['usuario'])) {
    unset($_COOKIE['usuario']);
    setcookie('usuario', null, -1, '/');
    return true;
} else {
    return false;
}
  • 1

    Vlw dude, I figured out what my problem was, I was expiring the cookie in another directory so I figured it should be expired in the same directory where it was created, gets the hint if someone has the same problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.