codeigniter csrf error on form submission

南楼画角 提交于 2019-12-04 17:18:29

you are doing it wrong.

try this

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

the value must be what codeigniter calculates for the csrf token.

or use form helper and codeigniter will add this hidden field automatically.

In my case I just increased 'csrf_expire' variable - the number in seconds the token should expire.

From $config['csrf_expire'] = 7200; To $config['csrf_expire'] = 28800;

change $config['csrf_regenerate'] = TRUE;

to

$config['csrf_regenerate'] = FALSE; in config file

If you just want to get rid of the errors altogether...
The easiest solution to get around them would be to:

  1. Open your /config/config.php file

  2. Find the line below:
    $config['csrf_protection'] = TRUE;

  3. Replace it with...
    $config['csrf_protection'] = FALSE;

  4. Save changes.


CAUTION: Turning off the CSRF protection means you are left open to CSRF attacks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!