We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Cookies with domain set cannot been deleted

Hello all,

I found a problem this morning is that a cookie set with a domain cannot been removed by delete() function:

$expire = time() + 86400 * $this->config->user->rememberDays;
$this->cookies->set('RMU', $user->id, $expire, "/", false, $this->config->cookie->defaultDomain);
$this->cookies->set('RMT', $token, $expire, "/", false, $this->config->cookie->defaultDomain);

It's not work use:

    if ($this->cookies->has('RMU')) {
        $this->cookies->get('RMU')->delete();
    }
    if ($this->cookies->has('RMT')) {
        $this->cookies->get('RMT')->delete();
    }

What's the problem?



16.0k
Accepted
answer
edited Jul '15

I'm not sure what's the point in getting the cookie and then deleting it when you could delete it directly. Try: $this->cookies->delete("RMT");