![]() |
Since you are using already the has_cookie() function, I'm assuming you are using the development version of CI4 because this helper is not available in v4.1.1 and below.
I don't know your use case for using has_cookie() but be mindful that this function checks if a Cookie object is still in the current Response object. When you call set_cookie() in a method then calls has_cookie() in another method, the cookies are already dispatched. By dispatch I mean the cookies are already registered with PHP. After dispatch, the Response clears out this collection of cookies. So you should know by now that has_cookie will check your cookie name against an empty collection, thus returning false. If your use case rather is to check if the cookie you set in one method is registered into PHP via the $_COOKIE array, then you need to use the get_cookie() function instead. This verifies the cookie against the Request class. This returns null if the cookie is not found in the $_COOKIE array. |
Messages In This Thread |
has_cookie helper always return false? - by mylastof - 05-07-2021, 04:57 AM
RE: has_cookie helper always return false? - by paulbalandan - 05-07-2021, 01:03 PM
|