CSRF regenerate with AJAX |
02-06-2023, 08:46 PM
(This post was last modified: 02-06-2023, 08:52 PM by 007basaran. Edit Reason: Additional Info )
Hello,
Maybe I didn't understand this question, but I wanted to talk about a problem I had before and its solution. When I tried to send an AJAX request using Codeigniter, I was getting 403 Forbidden Error because the csrf token was not renewed after the 1st request, then I produced the following solution, I got some code from you, you can use it if it works for you. For using AJAX requests on Codeigniter 4, if you are using CSRF TOKEN for security, you just need refresh CSRF TOKEN for post replies. You can add this function in your any helper class. Code: if (! function_exists('zs_refreshcsrf')) { Warning message function with bootstrap, i using this and you can use in any helper this code : Code: if (! function_exists('zs_alertboost')) { When users get any error from the controller, or the controller when returned with some data`s, if you not update csrf token you can get 403 Forbidden error. You just need use this function in the controller before alerting to the user. Code: if (! $this->validateData($post, $validation_rules)) { |
Messages In This Thread |
CSRF regenerate with AJAX - by Leo - 04-14-2020, 03:40 PM
RE: CSRF regenerate with AJAX - by Gary - 04-14-2020, 06:49 PM
RE: CSRF regenerate with AJAX - by Leo - 04-14-2020, 11:34 PM
RE: CSRF regenerate with AJAX - by entis - 04-15-2020, 08:02 AM
RE: CSRF regenerate with AJAX - by Gary - 04-15-2020, 12:09 PM
RE: CSRF regenerate with AJAX - by Leo - 04-15-2020, 12:30 PM
RE: CSRF regenerate with AJAX - by Morgun_Andrey - 05-05-2020, 02:39 PM
RE: CSRF regenerate with AJAX - by Gary - 04-15-2020, 01:17 PM
RE: CSRF regenerate with AJAX - by 007basaran - 02-06-2023, 08:46 PM
RE: CSRF regenerate with AJAX - by SubrataJ - 02-06-2023, 10:44 PM
RE: CSRF regenerate with AJAX - by Leo - 02-07-2023, 01:06 PM
RE: CSRF regenerate with AJAX - by Gary - 02-26-2023, 10:27 AM
|