Cookies

Response Cookies

The Phalcon\Http\Response offers a collection to store and manipulate cookies. You can then send those cookies back with the response.

To set up cookies you will need to instantiate a Phalcon\Http\Response\Cookies object or any object that implements the Phalcon\Http\Response\CookiesInterface.

Configurations

# set true to enable cookies encryption
COOKIES_USE_ENCRYPTION=true

# signKey must be at least 32 characters long
COOKIES_SIGN_KEY=#1dj8$=dp?.ak//j1V$~%*0XaK\xb1\x8d\xa9\x98\x054t7w!z%C*F-Jk\x98\x05\\\x5c

# define your own service provider
PROVIDER_COOKIES=\Zemit\Provider\Cookies\ServiceProvider

NOTE: The signKey MUST be at least 32 characters long, and it always helps if it is generated using a cryptographically secure pseudo random generator. You can always use the Crypt component to generate a good signKey.

Usage

// if the class is aware of injections
$cookies = $this->cookies;

// if the container is present
$cookies = $this->di->get('cookies');

// from outside
$cookies = Di::getDefault()->get('cookies');

API References

Phalcon\Http

Sources

Last updated