cookie won't set - 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: cookie won't set (/showthread.php?tid=17665) |
cookie won't set - El Forum - 04-11-2009 [eluser]SomeFunkyDude[/eluser] I tried making a controller called "cookie" that sets a cookie in the constructor, then making a simple page2() segment that displays whether the cookie was set or not, but the cookie state keeps returning FALSE Code: <?php cookie won't set - El Forum - 04-11-2009 [eluser]bretticus[/eluser] My advice would be don't set the cookie in your constructor. Cookies are not available on the same page load. calling any method in your controller class runs the set cookie code again. I don't know the ins and outs of the cookie helper functions, but I'd assume that would be your issue. If you have to absolutely want to set the cookie in your constructor, at least use your Code: if (get_cookie('myprefix_cookie_name') === TRUE) cookie won't set - El Forum - 04-11-2009 [eluser]SomeFunkyDude[/eluser] okay, i revised the cookie to be set only if get_cookie('myprefix_cookie_name') returns false. Apparently Code: if (get_cookie('myprefix_cookie_name') === TRUE) Code: if (get_cookie('myprefix_cookie_name') === FALSE) I tried Code: if (get_cookie('myprefix_cookie_name') { execute code } Code: <?php cookie won't set - El Forum - 04-11-2009 [eluser]bretticus[/eluser] Manual says... Quote:The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist. So that makes sense. Glad you got it working. In cases like this you can always get a true statement like: Code: if (get_cookie('myprefix_cookie_name') !== FALSE) cookie won't set - El Forum - 09-05-2012 [eluser]coder_elite[/eluser] how to make the cookie be available in other controller? for example Controller 1 - (this is where the cookie is set using set_cookie()) then after the cookie is set in Controller 1 ,redirect to Controller 2.how can i get the cookie (which is set in controller 1) in controller 2. cookie won't set - El Forum - 09-05-2012 [eluser]CroNiX[/eluser] http://ellislab.com/codeigniter/user-guide/helpers/cookie_helper.html http://ellislab.com/codeigniter/user-guide/libraries/input.html |