I have been trying like this –
// ================
// = set a Cookie for the users city =
// ================
function set($cityId = null){
$this->components[] = 'RequestHandler';
$this->components[] = 'Cookie';
$this->Cookie->name = 'Exampleoffers';
//$this->Cookie->time = 3600; // or '1 hour'
//$this->Cookie->path = '/bakers/preferences/';
$this->Cookie->domain = 'www.example.co.uk';
$this->Cookie->secure = false;
$this->Cookie->key = 'kkjdDqSI232qs*&sXOw!';
$cities = ($this->City->find('list'));
if($cities[$cityId]) {
$this->Cookie->write ("Deal.city_id", (int) $cityId, false, "+2 months");
} else {
$this->Cookie->write ("Deal.city_id", key($cities), false, "+2 months");
}
however, I am not sure if it is clashing with my Authsome cookie (?) or something else, but I am unable to read this value back.
Is there some way to specify which cookie you want to read() from in CakePHP?
Is there a way to have a cookie with 2 diffferent values of expiry times? – i.e. a cookie has User.id with a expiry of 1 week, and a Deal.city_id with a expiry of 2 months, say? Or am I right to think I DO need 2 cookies?
many thanks for any tips. It’s cake 1.3 btw !
You can, remember cookies are saved on the system so if you only save the cookie one time on that system it will have the set values, however, you cannot have 2 cookies with the same name set, which means that when you go and save the cookies you’ll have to do this:
If you don’t, one will overwrite the other.
EDIT: Adding some links in case you have more doubts:
API page of CookieComponent: http://api13.cakephp.org/class/cookie-component
Cookbook page of CookieComponent: http://book.cakephp.org/view/1280/Cookies