Welcome Guest, Not a member yet? Register   Sign In
CI4 Helper Function set_cookie doesn't create a cookie on browser
#4

I have good news for you. I understand your problem and I have the solution of your problem.
You are creating login for your application and after valid information you are trying to create cookie for logged in user.
After creating cookie you try to redirect the page, As I understand your problem. Here a short trick will do the work.
When you are redirecting instead of simply redirecting use below code:
PHP Code:
redirect()->to('url')->withCookies(); 

It will send cookie with redirect. Hence cookie will successfully generated in the browser.
Hope it solved your problem.
In CodeIgniter 4, I feel there should be more work on documentation. It's not completed yet. I get into this issue, and try many solutions but didn't get it right. After searching a lot, I just got the trigger. It should be mentioned in cookie helper with reference that when redirecting happens cookie should be sent along request. So that developer can understand how cookies work in CodeIgniter 4.
Reply


Messages In This Thread
RE: CI4 Helper Function set_cookie doesn't create a cookie on browser - by zeeforum - 06-21-2021, 03:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB