CodeIgniter Forums
set_cookie not working or am I missing something? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: set_cookie not working or am I missing something? (/showthread.php?tid=75754)



set_cookie not working or am I missing something? - aybarsm - 03-12-2020

Hello all,

https://forum.codeigniter.com/thread-73563.html => Is this an ongoing issue?

I am not able to set_cookie with cookie helper and then redirect.

PHP Code:
private function setCookieClient($client)
{
    
helper('cookie');
    
set_cookie($this->cookieName$client['remember_token'], (strtotime($client['remember_expires'])-time()));
    
set_cookie('Static''TestMe'86400);
}

return 
redirect()->redirect(route_toFixed('dashboardClient'))->with('notify', ['type'=>'success','message'=>'Success!']); 

Calling setCookieClient function and then calling redirect function not working at all. setCookieClient is a custom Auth Lib function however running set_cookie in the controller itself does not work either.

The only working solution was like the I mentioned previously.

PHP Code:
$this->response->setCookie(service('AuthClient')->cookieName$authstat['client']['remember_token'], abs(strtotime($authstat['client']['remember_expires'])- time() ))->setHeader('Location'route_toFixed('dashboardClient')); 


Or am I missing something else here?


RE: set_cookie not working or am I missing something? - aybarsm - 03-13-2020

Ok, as far as I am concerned https://github.com/codeigniter4/CodeIgniter4/issues/1393 -> the problem still persists. Yes it is possible to set cookie with redirect() however it is not possible to delete it. Yet, since there is no With, WithInput, to and back methods directly in Response, it seems I need to find a way to alter redirect() common function.