如何使用PHP(codeigniter)启用csrf_protection的ajax帖子 [英] How to use ajax post with PHP (codeigniter) enabling csrf_protection

查看:93
本文介绍了如何使用PHP(codeigniter)启用csrf_protection的ajax帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个使用ajax.post方法发布一些数据的页面。



我正在使用codeigniter。我已启用csrf保护为真。



我收到 403(禁止)错误。



我尝试过:



CSRF配置为:



$ config ['csrf_protection'] = true;

$ config ['csrf_token_name'] ='csrf_test_name';

$ config ['csrf_cookie_name'] ='csrf_cookie_name';

$ config ['csrf_expire'] = 7200;



我试过正常发布为:





 $ .post('  http:// localhost / pro352 / agent / book_service /',{service_id:service_id}, function (data){
$(' #badge')。text(data);
});





请帮帮我!

解决方案

config ['csrf_protection'] = true;


config ['csrf_token_name'] ='csrf_test_name';


< blockquote> config ['csrf_cookie_name'] ='csrf_cookie_name';


I am creating a page that posts some data as with ajax.post method.

I am using codeigniter. I have enabled csrf protection true.

I am getting 403 (Forbidden) error.

What I have tried:

CSRF config is :

$config['csrf_protection'] = true;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;

I have tried to post normaly as :


$.post('http://localhost/pro352/agent/book_service/',{service_id:service_id},function(data){
              $('#badge').text(data);
                });



please help me!

解决方案

config['csrf_protection'] = true;


config['csrf_token_name'] = 'csrf_test_name';


config['csrf_cookie_name'] = 'csrf_cookie_name';


这篇关于如何使用PHP(codeigniter)启用csrf_protection的ajax帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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