关于yii2 _csrf验证【这个是网上看到的】
作者:互联网
//js里
1、<input type="hidden" value="<?php echo Yii::$app->request->csrfToken; ?>" name="_csrf" >
2、
function getMessage(){
$.ajax({
headers:{
"<?php echo \Yii\web\Request::CSRF_HEADER;?>":
'<?php echo Yii::$app->request->csrfToken; ?>' // _csrf验证
},
type: 'post', //传输类型
url: "/site/ajax-message",
async: true,
data: {
start:0
},
dataType: "jsonp",
success: function (data) {
consolr.log(data)
}
});
}
//php里
1、main.php
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'enableCookieValidation' => true,
'cookieValidationKey' => 'cookvalid',
],
]
2、控制器中添加:
public $enableCsrfValidation = false;
标签:function,php,验证,request,ajax,csrf,yii2,data 来源: https://blog.csdn.net/luxiaobo_1/article/details/118680649