CodeIgniter Forums
Cookie codeigniter 4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Cookie codeigniter 4 (/showthread.php?tid=81689)



Cookie codeigniter 4 - devo - 04-10-2022

How can i get the csrf cookie in the browser ?
When i try access the cookie in the brwoser use javascript document.cookie i got nothing


RE: Cookie codeigniter 4 - kenjis - 04-10-2022

You can't use document.cookie, because of security reason.

Get it from HTML tag.
See https://codeigniter4.github.io/userguide/libraries/security.html#html-forms


RE: Cookie codeigniter 4 - devo - 04-10-2022

i need solution about regenerate csrf token on ajax
so do you have the best solution for handel regenerate csrf token on ajax ??
because sometime if i filter / search the form i got error 403 issue about csrf token

btw how if i don't make csrf token regenrate it is save for my application??


RE: Cookie codeigniter 4 - seunex - 04-10-2022

Use header to send the csrf token via ajax. U can add the csrf_meta() helper to your meta tag and use header in ur ajax the get the meta and send it via ajax.

I do that alot.


RE: Cookie codeigniter 4 - devo - 04-11-2022

(04-10-2022, 11:53 PM)seunex Wrote: Use header to send the csrf token via ajax. U can add the csrf_meta() helper to your meta tag and use header in ur ajax the get the meta and send it via ajax.

I do that alot.
i try this already, but i need regenerate csrf token real time, like i said sometime in my form filter / search error because of csrf token,
or do you have example?

(04-10-2022, 08:52 PM)kenjis Wrote: You can't use document.cookie, because of security reason.

Get it from HTML tag.
See https://codeigniter4.github.io/userguide/libraries/security.html#html-forms

i need solution about regenerate csrf token on ajax
so do you have the best solution for handel regenerate csrf token on ajax ??
because sometime if i filter / search the form i got error 403 issue about csrf token


btw how if i don't make csrf token regenrate it is save for my application??


RE: Cookie codeigniter 4 - seunex - 04-11-2022

You can get the new csrf token by using the helper named csrf_hash()


RE: Cookie codeigniter 4 - InsiteFX - 04-11-2022

Makeitweb - How to Send AJAX request with CSRF token in CodeIgniter 4