Home > Article > Backend Development > php yii framework post csrf
Friends in the Tieba group encountered this problem today.
When he submitted using ajax post, it would throw 400
Then he found a solution on the yii forum
But the _csrf passed was undefined . Seeing this, I knew what was going on. The corresponding object was not found for this jq.
<?php echo Yii::app()->getRequest()->getCsrfToken(); ?>directly assigns it to the value of this csrf token. Finally, a verification prompt appeared.
Verification error. Eighty percent of the time it is not this parameter name. See if this thing is saved in the cookie session.
I did find this ghost in cookie.
I haven’t played this thing much either. Try changing the parameter name to YII_CESRF_TOKEN.
Then click submit and it’s over.
csrf is a built-in tool in Yii to prevent cross-domain attacks. The main principle is to give an encrypted value. First verify that the value exists. is it right or not. Then process the form and other operations.
The above introduces the php yii framework post csrf, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.