csrf_token works in one page but not in other - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: csrf_token works in one page but not in other (/showthread.php?tid=76759) |
csrf_token works in one page but not in other - Freizello - 06-16-2020 i have two pages in a same codeigniter 3 project with a controller, and a child view each, but using a same template. This two page have identical controller, and child view (just for testing, because on real case, they really have same behaviour and code). Page 1 : http://localhost/project-name/register-page1/form/ Page 2 : http://localhost/project-name/register-page2/form/ on page 1, ajax with csrf_token() works without a problem. but with the same code in page 2, it didn't work and said 403 forbidden when accessing a method from ajax request. I don't know why my code working on page1, but not working on page2 with error 403 forbidden. Please help me... Code: POST http://localhost/project-name/register-page2/getKabupatenByProvinceName 403 (Forbidden) on config.php setting PHP Code: $config['csrf_protection'] = TRUE; register-page1 and register-page2 ajax controller PHP Code: public function getKabupatenByProvinceName() register-page1 and register-page2 ajax request on view Code: $('#provinsi').change(function() { register-page1 and register-page2 ajax function to get and refill csrf_token Code: function get_token() { Code: function refill_token() { RE: csrf_token works in one page but not in other - InsiteFX - 06-18-2020 Read this: Regenerate CRSF token codeigniter on submit Ajax |