• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with cookie in CI4

#1
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.
Reply

#2
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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
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.
Reply

#4
Cookies only update on a page refresh that is why it worked when you loaded a view.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.