Welcome Guest, Not a member yet? Register   Sign In
Problem trying to store cookie in Codeigniter 4
#1

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'));
        
Reply
#2

Cookies do not update until there is a page refresh.

Refresh your page and see if it is there.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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

(This post was last modified: 04-14-2020, 01:22 PM by Leo.)

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
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB