I’ve searched here and on google before asking this cause I see its a popular question, but the answers I have found I have tried, and still I am failing.
This is my attempt to set the cookies (note the helper is autoloaded)
$longlife = 60*60*24*60; //60 days
$shortlife = 60*60*24*10; //10 days
$this->input->set_cookie('AutoRemember', $user.'::'.$hashbrown, $shortlife, '.example.com', '/');
$this->input->set_cookie('LongRemember', $user.'::'.$hashbrown, $longlife, '.example.com', '/');
when I attempt to do a var_dump on ‘$this->input->cookie()` i get bool false as an output, meaning no cookies found. This is the first time i’ve tried using cookies with CI so the issue is beyond me at the moment.
also note I changed the real domain in the example above to example.com as I don’t want the domain to show up in searches right now.
__ Edited Oct 3, 2013 For Claritiy __
Alright, I figure out what my problem was, and I am sure this will help new comers down the road as well. So, when your initially setting up your
application/config/config.phpYou will find a line:
This setting while given the impression is optional, is as it turns out more of a requirement. There appears to be a bug, of which is not always reproducible, so its hard to track what and why. Bottom line is though, if this config item is not set. On a good handful of occasions while the cookie is setting/getting it will break silently under the hood. Leaving you with the impression that it is working when it isn’t.
Imagine how frustrating that can be. Anyway, my fix for the original problem was to set the prefix line mentioned above. Anything will do, coders choice.
Anyway, note worthy mention for those intent on setting it. When you set a cookie you do it normally as per the document/guide.
However, what I noticed the document doesn’t specify (or didn’t last I checked) was that the prefix you set
will not get you the cookie value when you call it like one would think they should which the doc says to do ie:
calling the value out like this will most likely result in seeing nothing on the screen. If you did a
var_dump()for example. you would getbool(false). In other words meaning it can’t find the cookie your referencing. Which is true. It can’t it doesn’t exist, remember you set a prefix. To get your cookie at that point you will need to do something likewhich will print out the actual value of the cookie.