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

(04-20-2020, 03:18 PM)Leo Wrote: I was able to set and read a cookie just fine with your stripped code. You probably have a problem with your getConfig() function. Heres a stripped to barebones code that worked. Just build your code up until you find the problem. Try and echo out getConfig('auth_cookie_expiry') and see if you get the correct value? Also your XSS_Clean set to true looks suspicious on the get_cookie() func. switch it to false maybe?

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

        // store encrypted key in cookie
        set_cookie([
            'name' => 'auth_cookie_key',
            'value' => 'value_of_encrypted_cokie',
            'expire' => time() + 1000,
            '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'];
        }
    

Also try this extension in chrome. It really eases process of testing cookies.
http://www.editthiscookie.com/


I just used your code in my code but not working also
Reply


Messages In This Thread
RE: Cookie not working in codeigniter 4. Need helper - by Chivinsdev - 04-20-2020, 03:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB