CodeIgniter Forums
Problem with cookie in CI4 - 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: Problem with cookie in CI4 (/showthread.php?tid=76947)



Problem with cookie in CI4 - seunex - 07-06-2020

I still could not understand why i find it add to set cookie in codeigniter 4

PHP Code:
helper('cookie');
      $identifier = [
      'name' => 'identifier',
      'value' => $uid,
      'expire' => time()+ (10 365 24 60 60),
      'httpOnly' => true
    
];

    $token = [
    'name' => 'token',
    'value' => $rememberMeToken,
    'expire' => time()+ (10 365 24 60 60),
    'httpOnly' => true
  
];

set_cookie($identifier);
set_cookie($token); 


Now i try get the cookie by use get_cookie('token') i always get nothing in return.


RE: Problem with cookie in CI4 - InsiteFX - 07-07-2020

httponly
When TRUE the cookie will be made accessible only through the HTTP protocol. This means that the cookie won't be accessible by scripting languages, such as JavaScript. It has been suggested that this setting can effectively help to reduce identity theft through XSS attacks (although it is not supported by all browsers), but that claim is often disputed. Added in PHP 5.2.0. TRUE or FALSE


RE: Problem with cookie in CI4 - seunex - 07-07-2020

That not the issue I notice that if you set cookie an then use redirect after seting cookie on my side the cookie will not be set.

I was able to set cookie if I only return a view not return redirect.


RE: Problem with cookie in CI4 - InsiteFX - 07-07-2020

Cookies only update on a page refresh that is why it worked when you loaded a view.