0
I don’t know what mistake I’m making when creating a class, but I’m not able to delete the cookie with my class.
public function cookie($name, $value = 'nome', $expire = NULL, $path = '/', $domain = NULL, $secure = FALSE, $httponly = TRUE) {
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
return $this;
}
public function delete($name){
unset($_COOKIE[$name]);
// empty value and expiration one hour before
setcookie($name, NULL, -1);
//return var_dump($_COOKIE);
}
$cs->cookie('meu', 'sd', time()+1800);
$cs->delete('meu');
I don’t know why else in my browser the cookie is not deleted, what I’m doing wrong?
Ricardo, I honestly don’t understand. The cookie keeps popping up in Chrome (even an extension) and Firefox, but when I try to find the name and see that it exists, it says it doesn’t exist. But the cookie keeps popping up. When I don’t use the class, it removes the cookie and is left with nothing. I wonder what’s wrong?
– abcd
Okay, I figured it out! In addition to the cookie name you must also pass the value and the path:

function delete($name, $value = 'nome', $expire = NULL, $path = '/', $domain = NULL, $secure = FALSE, $httponly = TRUE) {
 unset($_COOKIE[$name]);
 setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
 }
delete('omeucookie', 'sd', 1);

– Ricardo Cruz
I ran some tests here, and in my case it’s
path
which is jamming everything, when I pass it, it removes the cookie. Hugs...– abcd