You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a common pitfall with cookies. Quoting PHP.net:
Cookies will not become visible until the next loading of a page that the cookie should be visible for.
CI4's set_cookie sets a new cookie in the Response object but it sits there until the headers are sent. get_cookie uses the Request object to retrieve the cookie in the $_COOKIE array. In your example, since you are setting and getting the same cookie on the same page, then cookies are not sent to the browser and therefore the $_COOKIE is not populated with the cookies in the Response. That's why you are getting null (i.e., cookie not in $_COOKIE).
To achieve your desired result, create two pages: (1) setting the cookie; (2) getting the cookie. In your cookie-setting page, you will redirect with cookies to the cookie-getting page, something like redirect('/my-cookie-getter')->withCookies();. Then, there the dd should show the cookies.
Side note: The arguments order supplied in set_cookie in your example is wrong.
cookie helper not working,
I tried to refresh the browser, but the result was the same // null
The text was updated successfully, but these errors were encountered: