CodeIgniter Forums
Can't use cookie helper in CI 4.0.4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Can't use cookie helper in CI 4.0.4 (/thread-77089.html)

Pages: 1 2


Can't use cookie helper in CI 4.0.4 - zoom360 - 07-18-2020

I can't use from helper cookie CI4:

Code:
delete_cookie();
get_cookie();
set_cookie()

But I can using $_COOKIE, from CI 4.0.3.

Code:
setcookie();

However, I can only setCookie and not change it from CI 4.0.4.


RE: Can't use cookie helper in CI 4.0.4 - InsiteFX - 07-18-2020

Did you load the cookie helper in the BaseController ?

I just tested the cookies and they work fine CI 4.0.4


RE: Can't use cookie helper in CI 4.0.4 - zoom360 - 07-18-2020

(07-18-2020, 03:45 AM)InsiteFX Wrote: Did you load the cookie helper in the BaseController ?

I just tested the cookies and they work fine CI 4.0.4
I have loaded it. I can create a cookie, added new cookie. But I can't change or reset it.


RE: Can't use cookie helper in CI 4.0.4 - InsiteFX - 07-19-2020

It works I just did it, When you first write a cookie the web page needs to be refreshed
to update the cookie:

PHP Code:
// To delete cookie
        //set_cookie('test', '', time()-3600);

        // Create first cookie
        //$data = 'TEST';

        //set_cookie('test', $data, time()+3600);

        //echo get_cookie('test');

        // Create second cookie NOTE you need to click refresh in your browser to see it.
        
$data 'TEST2';

        
set_cookie('test'$datatime()+3600);

        echo 
get_cookie('test'); 

Those are the test steps I took when I create the updated second cookie I had to refresh my
web browser for it to show the updated cookie value.


RE: Can't use cookie helper in CI 4.0.4 - Didytz - 07-20-2020

Hi,
I have same problem.

I have included helper("cookie") but it is not setting nor deleting cookie.

But If I use standard PHP  "setcookie...." it works fine. So basically I have same problem as OP.

UPS, my bad. I am still using 4.0.3 and it seems that i need 4.0.4 for set_cookie...


RE: Can't use cookie helper in CI 4.0.4 - InsiteFX - 07-21-2020

When working with cookies you need to do a web browser refresh to see the cookie update.


RE: Can't use cookie helper in CI 4.0.4 - Didytz - 07-21-2020

(07-21-2020, 03:22 AM)InsiteFX Wrote: When working with cookies you need to do a web browser refresh to see the cookie update.

I know that and I do refresh but it seems that something is not working with cookie helper as I am.abel.to set cookie directly with php setcookie(....) And it is working that way.


RE: Can't use cookie helper in CI 4.0.4 - InsiteFX - 07-21-2020

What I posted above works here using the CodeIgniter developer version.

This is a Windows 10 Pro x64 system using XAMPP Cookies work fine here.

Check you app/Config/app.php file and check your cookie settings.


RE: Can't use cookie helper in CI 4.0.4 - kilishan - 07-23-2020

Are you stopping execution of the script with a dd(), die(), etc? If so that would stop the cookies from being sent or updated.


RE: Can't use cookie helper in CI 4.0.4 - Didytz - 07-23-2020

(07-23-2020, 07:00 AM)kilishan Wrote: Are you stopping execution of the script with a dd(), die(), etc? If so that would stop the cookies from being sent or updated.
No