Prevent cookie deleted when browser close - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Prevent cookie deleted when browser close (/showthread.php?tid=86124) |
Prevent cookie deleted when browser close - nicojmb - 01-12-2023 Hi, I've a simple funcion to set a coookie to save GPDR status. PHP Code: set_cookie('myweb_gpdr', 'accepted', 0); This work great but if a close browser and reopen, the cookie not exists. Can you helpme? version: 4.3 RE: Prevent cookie deleted when browser close - superior - 01-12-2023 You are telling the cookie function to expire after 0 seconds. (3th parameter) See: https://codeigniter.com/user_guide/helpers/cookie_helper.html#set_cookie RE: Prevent cookie deleted when browser close - nicojmb - 01-12-2023 (01-12-2023, 11:27 AM)superior Wrote: You are telling the cookie function to expire after 0 seconds. (3th parameter) You are right, I thought "0" was permanent. Changed to YEAR constant and work as spected. PHP Code: set_cookie('myweb_gpdr', 'accepted', YEAR); Regards! RE: Prevent cookie deleted when browser close - kenjis - 01-12-2023 (01-12-2023, 11:27 AM)superior Wrote: You are telling the cookie function to expire after 0 seconds. (3th parameter) No. If the cookie expires after 0 seconds, you cannot use the cookie data at all. If set to 0, the cookie will only last as long as the browser is open. |