*Tip:CSRF + Ajax - 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: *Tip:CSRF + Ajax (/showthread.php?tid=63927) |
*Tip:CSRF + Ajax - BrendanRehman - 12-23-2015 Hi Guys, This is a quick post on how to setup CSRF protection and Ajax in your CI app. When you set the PHP Code: $config['csrf_protection'] = TRUE; So here's the fix for when you want this to work with all your Ajax calls. 1. Add following code inside your html head tag in your master template or where ever you will be using ajax. PHP Code: <?php 2. Setup your ajax, this happens before any ajax requests are made. Code: <script> Voila! You're done, all your ajax requests are CSRF protected. Enjoy, Brendan |