Ajax CSRF 403禁用代码指示器 [英] Ajax CSRF 403 forbidden codeigniter

查看:157
本文介绍了Ajax CSRF 403禁用代码指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的ajax代码

  $('#classes')。change(function(){
$ classes = $(this).val();
$。 ajax({
type:POST,
data:{
'<?php echo $ this-> security-> get_csrf_token_name();?>':'< ;?php echo $ this-> security-> get_csrf_hash();?>',
'class':$ classes
},
url:&php echo base_url();?" index.php / admin / getsection /+ $ classes,
success:function(return_data)
{
// alert(return_data);
$('#section')。html('');
$('#section')。html(return_data);
$('#section')。 $ b}
});



当我第一次调用ajax函数时,完善。但是当我再次运行相同的函数时,它将返回403禁止的错误。



请指导我做什么

解决方案

文档< a>:


令牌可以在每次提交时重新生成(默认),或者在CSRF Coo​​kie的整个生命周期中保持相同。标记的默认重新生成提供了更严格的安全性,但可能会导致可用性问题,因为其他标记变得无效(后退/前进导航,多个标签/窗口,异步操作等)。您可以通过编辑以下配置参数来更改此行为

  $ config ['csrf_regenerate'] = TRUE; 


将其设置为FALSE。


Hello I am calling controller to get section using AJAX in my codeigniter based app which have CSRF Enable

my ajax code

    $('#classes').change(function(){  
  $classes=$(this).val();
            $.ajax({
             type:"POST",
             data:{
                 '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>',
                 'class':$classes
             },
             url:"<?php echo base_url();?>index.php/admin/getsection/"+$classes,
             success:function(return_data)
             {
                //alert(return_data);
                $('#section').html('');
                $('#section').html(return_data);
                $('#section').val(section);
             }
    });

When I Call ajax function first time, it will run perfect. but when i run the same function again, it will return 403 forbidden error.

Please advice what I do

解决方案

From the docs:

Tokens may be either regenerated on every submission (default) or kept the same throughout the life of the CSRF cookie. The default regeneration of tokens provides stricter security, but may result in usability concerns as other tokens become invalid (back/forward navigation, multiple tabs/windows, asynchronous actions, etc). You may alter this behavior by editing the following config parameter

$config['csrf_regenerate'] = TRUE;

Set that to FALSE.

这篇关于Ajax CSRF 403禁用代码指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆