Welcome Guest, Not a member yet? Register   Sign In
How to work with cookie and redirect in codeigniter 4
#1

(This post was last modified: 09-10-2021, 05:50 AM by venance.)

Hello everyone. I'm working with codeigniter4 where I want to be able to store cookie and then redirect
to another page. If I set a cookie without including redirection process, Cookie stores successfully, But the issue is when I do redirection, the cookie did't saved anymore.
How can I solve and make cookie saved and redirect

PHP Code:
public function loginProcessor(){
    helper(['cookie']);
    $checkStatus true;

    if ($checkStatus){
        set_cookie('nameCookie''CookieSomething'time() + 60*60*24*30);
    }
    return redirect()->to('dashboard');

Reply
#2

Your if statement is always true with checkStatus because you are setting it to true all the time in the method.

It will never reach the else clause.

It would also help if you explain what you want to do with the cookie etc;
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

I have solved my issue by using php function
PHP Code:
setcookie() 
or using
PHP Code:
redirect()->to('urlname')->setCookie("name""value"time()); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB