![]() |
Basic Cookie Help - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Basic Cookie Help (/showthread.php?tid=7277) |
Basic Cookie Help - El Forum - 04-01-2008 [eluser]Jim Higgins[/eluser] I'm having a bit of trouble accessing a cookie using the Cookie Helper. After loading the helper of course, should this work? $this->_state = 'Some State Name'; set_cookie('state_cookie', $this->_state); echo 'Get cookie = ' . get_cookie('state'); The get cookie returns nothing. I'm not receiving any errors. I stripped everything down to the basics here. Basic Cookie Help - El Forum - 04-01-2008 [eluser]Jay Turley[/eluser] [quote author="Jim Higgins" date="1207106975"]I'm having a bit of trouble accessing a cookie using the Cookie Helper. After loading the helper of course, should this work? $this->_state = 'Some State Name'; set_cookie('state_cookie', $this->_state); echo 'Get cookie = ' . get_cookie('state'); The get cookie returns nothing. I'm not receiving any errors. I stripped everything down to the basics here.[/quote] Just guessing, really, since I have yet to use the CI cookie functions, but shouldn't you use the same name for the retrieval as for the setting? Code: $this->_state = 'Some State Name'; Basic Cookie Help - El Forum - 04-01-2008 [eluser]Jim Higgins[/eluser] Yeah. I am. Sorry. I made a mistake when simplifying for the post. Here's what it actually looks like... if ($this->input->post('state')) { $this->_state = $this->input->post('state'); set_cookie('state_cookie', $this->_state); echo 'Get cookie = ' . get_cookie('state_cookie'); } Basic Cookie Help - El Forum - 04-02-2008 [eluser]Jay Turley[/eluser] Okay, first of all, naming the cookie state_cookie caused me to get the mysterious "Disallowed Key Characters." error message, indicating that name conflicts with another cookie I already have in IE. Second, I found the following code to work perfectly: Code: set_cookie('squig', 'mybutt', '0'); However when I deleted the third "non-required" parameter, the expiration, the cookie did not work. Try adding the '0' (or however many seconds you want) as the third parameter to set_cookie. Basic Cookie Help - El Forum - 04-02-2008 [eluser]Jim Higgins[/eluser] Hey, you're right! I tried adding the 0 and it worked just fine. Thanks. |