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

(This post was last modified: 04-20-2020, 03:28 PM by Leo. Edit Reason: Clarity, switched array() with [] because we live in the 21st century )

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/
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-20-2020, 03:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB