CodeIgniter Forums
set_cookie() doesn't work with redirect() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: set_cookie() doesn't work with redirect() (/thread-72337.html)



set_cookie() doesn't work with redirect() - zjonsnowz - 12-06-2018

Hello,
This is my code:

PHP Code:
namespace App\Controllers;
use 
CodeIgniter\Controller;

class 
Home extends Controller
{
    public function 
__construct()
 
 {
 
   helper(['cookie']);
 
 }
    public function 
page1()
    {
        
set_cookie('test''testvalue-'.time(), time() + 86400);
        return 
redirect()->to('page2');
    }
    public function 
page2()
    {
        echo 
get_cookie('test');
    }


Redirect is working but there is no 'test' cookie on page2. Please help.