CodeIgniter Forums

Full Version: Problem trying to store cookie in Codeigniter 4
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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'
            echo 'already has one';
Cookies do not update until there is a page refresh.

Refresh your page and see if it is there.
I comment out set cookie and refresh my page is return null the cookie is gone instantly
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
Not too late I still can figure the issue bout till now thank I will try that.