Getting Codeigniter CSRF token without a form? Getting Codeigniter CSRF token without a form? codeigniter codeigniter

Getting Codeigniter CSRF token without a form?


You can get the CSRF token name and value via the security class:

$this->security->get_csrf_hash();$this->security->get_csrf_token_name();


Add it to the form this way

<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">


Here is an example that shows you how to enable CSRF Attack mode :

<script>      var cct = '<?php echo $this->security->get_csrf_hash() ?>';  var get_csrf_token_name = '<?php echo $this->security->get_csrf_token_name() ?>';     $.ajaxSetup({   type:'post',  data:{ <?php echo $this->security->get_csrf_token_name() ?> :cct}   });         var siteurl = '<?= site_url()?>';                  </script>