cookies and CI4 |
Hi!
`setcookie` is the native PHP function. `set_cookie` is CI4's cookie helper function. Behind the scenes, when calling `set_cookie`, you are actually building a cookie object to be saved in the Response class for dispatching later. Please note that cookie objects created by `set_cookie` are just sitting there in the Response class. They are not yet dispatched to the browser. That is why you are complaining the `set_cookie` does not work. It works its job but not the way you expect it to be. When you dispatch the cookies via the Response class, the Response calls CookieStore to actually do the dispatching (this will be changed in future versions where Response will do the dispatching). When the cookies are dispatched, under the hood it calls the native `setcookie` function which actually sets the cookies into the browser. This way the cookies are available for retrieval by `get_cookie` or thru access from the `$_COOKIE` array. In CI4, to make `set_cookie` actually work in your case, you need to have the saving and retrieval of cookies in two different places in your controller. The `set_cookie` code in one and the `get_cookie` in another. PHP Code: public function one() |
Messages In This Thread |
cookies and CI4 - by kristianlake - 07-14-2020, 06:19 AM
RE: cookies and CI4 - by kristianlake - 07-14-2020, 10:21 AM
RE: cookies and CI4 - by jreklund - 07-14-2020, 12:12 PM
RE: cookies and CI4 - by kristianlake - 07-14-2020, 01:06 PM
RE: cookies and CI4 - by GeorgeBunzi - 12-22-2021, 09:22 PM
RE: cookies and CI4 - by kenjis - 12-22-2021, 11:16 PM
RE: cookies and CI4 - by paulbalandan - 12-22-2021, 11:37 PM
RE: cookies and CI4 - by InsiteFX - 12-23-2021, 02:18 AM
RE: cookies and CI4 - by kenjis - 12-23-2021, 03:58 AM
|