CodeIgniter Forums
Problem trying to store cookie in Codeigniter 4 - 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: Problem trying to store cookie in Codeigniter 4 (/showthread.php?tid=76035)



Problem trying to store cookie in Codeigniter 4 - seunex - 04-09-2020

I have been trying to make use of cookie in my Codeingiter 4 Project. 

But when i set cookie cookie it set because i var dump it after setting it buh affter i set it and it remove the setting command and try to get the recently get cookie it return null.

How can we hold cookie in codeigniter 4?

PHP Code:
$cookie = [
            'name' => 'testes_cook',
            'value' => 'Hello world',
            'expire' => '86500'
        ];
        if($this->response->hasCookie('testes_cook'))
        {
            echo 'already has one';
        }
        else
        {
            $this->response->setCookie($cookie);
            var_dump($this->response->getCookie('testes_cook'));
        



RE: Problem trying to store cookie in Codeigniter 4 - InsiteFX - 04-09-2020

Cookies do not update until there is a page refresh.

Refresh your page and see if it is there.


RE: Problem trying to store cookie in Codeigniter 4 - seunex - 04-09-2020

I comment out set cookie and refresh my page is return null the cookie is gone instantly


RE: Problem trying to store cookie in Codeigniter 4 - Leo - 04-14-2020

Your expire is too short. Its gotta be expire in the future. Basically time() + 86500;
It's probably too late, and you figured it out but, maybe someone else stumbles in this problem, besides you...or me.
ex: setcookie('testes_cook', 'Cooking testes??', time() + 86500, '/', '', $secure); //$secure - true if https, false if http


RE: Problem trying to store cookie in Codeigniter 4 - seunex - 04-14-2020

Not too late I still can figure the issue bout till now thank I will try that.