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

Setting a cookie from ControllerBase?

I need an 'unique' identifier on many controllers, so I thought i'd do something like this:

class ControllerBase extends Controller
{
    public function initialize() {
        if (!$this->cookies->has('identifier')) {
            $this->cookies->set('identifier', uniqid(mt_rand(), true), time() + 15 * 86400);
        }
    }
}

It doesn't seem to work however? :/



98.9k

Check the output in the Chrome Developer Console to see it the cookie was not sent.