Welcome Guest, Not a member yet? Register   Sign In
Cookie not working in codeigniter 4. Need helper
#9

(This post was last modified: 04-21-2020, 05:58 AM by Leo.)

Weird. Is your CI4 composer installed or unzipped?

Try and add this 'domain' => ''
and maybe this 'secure' => false,

then test with this:

PHP Code:
public function testSetCookies()
    {
        helper('cookie');
        set_cookie([
            'name' => 'auth_cookie_id',
            'value' => 'value_of_cookie',
            'expire' => time() + 1000,
            'domain' => '',
            
'secure' => false,
            'httponly' => false
        
]);

        // store encrypted key in cookie
        set_cookie([
            'name' => 'auth_cookie_key',
            'value' => 'value_of_encrypted_cokie',
            'expire' => time() + 1000,
            'domain' => '',
            
'secure' => false,
            'httponly' => false
        
]);
    }

    public function testReadCookies()
    {
        helper('cookie');
        if (get_cookie('auth_cookie_id'true) && get_cookie('auth_cookie_key'true)) {
            echo $_COOKIE['auth_cookie_id'];
            echo '<br>';
            echo $_COOKIE['auth_cookie_key'];
        }
    

I just noticed that if I set any type of domain in cookie set up they wouldn't work. Please write back if that did it.

Also check what you have set up in App/Config
I have this:
PHP Code:
    public $cookiePrefix   '';
    public 
$cookieDomain   '';
    public 
$cookiePath     '/';
    public 
$cookieSecure   false;
    public 
$cookieHTTPOnly false
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply


Messages In This Thread
RE: Cookie not working in codeigniter 4. Need helper - by Leo - 04-21-2020, 05:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB