CodeIgniter Forums
redirect() function clears out any set_cookie - 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: redirect() function clears out any set_cookie (/showthread.php?tid=76731)



redirect() function clears out any set_cookie - burgoyn1 - 06-14-2020

If you set a cookie, then redirect to another page, the cookie does not get set. This used to work in codeigniter 3.

PHP Code:
helper'cookie' );
set_cookie'my_new_cookie''this is some cookie text'60 60 24 );

$redirect redirect();
$redirect->to'/cookie_check' );
return 
$redirect

If you set the cookie without the redirect, it works.

PHP Code:
helper'cookie' );
set_cookie'my_new_cookie''this is some cookie text'60 60 24 ); 

Also, if you use the built in php setcookie function, it works as expected

PHP Code:
setcookie'my_new_cookie''this is some cookie text'time() + 60 60 24 7'/');

$redirect redirect();
$redirect->to'/cookie_check' );
return 
$redirect