1.Enable csrf
application/config/config.php
$config[‘csrf_protection’] = FALSE; to $config[‘csrf_protection’] = TRUE;
and configuer other thing if you want.
2. Under<form> tag
1 | <input name="<?php echo $this->security->get_csrf_token_name(); ?>" type="hidden" value="<?php echo $this->security->get_csrf_hash(); ?>"> |
That’s All !!!!
csrf in in jquery CodeIgniter
Just need to send csrf name and it’s value.
1 2 3 4 5 6 7 8 9 10 11 12 13 | function addData(){ $csrf_name = '<?php echo $this->security->get_csrf_token_name(); ?>'; $csrf_value = '<?php echo $this->security->get_csrf_hash(); ?>'; $proName = 'shirt'; $.ajax({ type: "POST", url: "<?php echo base_url(); ?>admin/addData", data:{proname:$proName,[$csrf_name]:$csrf_value}, success: function(res){ location.reload(); } }); } |
Why Codeigniter CSRF valid for only one time ajax request? or csrf in ajax error in multiple use.
You can set this in config.php
1 | $config['csrf_regenerate'] = FALSE; |