CSRF token 无法被验证. ----Yii连接数据库后数据库错误日志报错
CSRF token 无法被验证.
我使用的是mongodb+ yii1.1
What is CSRF, please see the details here. http://en.wikipedia.org/wiki/Cross-site_request_forgery
In Yii, how to start the CSRF authorization? It is very easy to do that.
Just add this to main.php
'components'=>array(
'request'=>array(
'enableCsrfValidation'=>true,
),
),
And then, do something else to send a request to the server, you have to provide the YII_CSRF_TOKEN ( the browser will do for us when click a link), otherwise, you will get this message
The CSRF token could not be verified.
when you post a form, if you do not use CActiveForm or its children, you have to provide a hidden field to store the YII_CSRF_TOKEN.
<input type="hidden" name="YII_CSRF_TOKEN" value="<?php echo Yii::app()->request->csrfToken; ?>" />
If you use CActiveForm or its children, you just use the same code no matter you set enableCsrfValidation to true or false.
如果你使用CActiveForm类或其继承的子类进行创建表单时,在POST提交数据的时候会有一个$_POST['YII_CSRF_TOKEN'] 字段,让程序识别这是程序合法的提交数据。
<?php $form=$this->beginWidget('CActiveForm'); ?>
<--表单信息-->
<?php $this->endWidget(); ?>
顺便补充一下:在使用CActiveForm时,可以自定义设置参数,
<?php $form = $this->beginWidget('CActiveForm', array(
'id' => 'register-form',
'action' => ['test/register'],
));?>
通过action选项设置当前表单数据的提交处理url. 详细参数可以参考参考手册
感谢原作者:http://www.cnblogs.com/davidhhuan/archive/2011/01/19/1939253.html
友情参考:http://blog.csdn.net/zm2714/article/details/8814663
CSRF token 无法被验证. ----Yii连接数据库后数据库错误日志报错的更多相关文章
- FastDFS整合nginx后,nginx一直报错
FastDFS整合nginx后,nginx一直报错: 报错内容: [2018-06-11 09:41:21] ERROR - file: ../common/fdfs_http_shared.c, l ...
- 普通的jdbc事务在插入数据后 下面的代码报错时 数据不会回滚 但是 spring的事务会回滚
普通的jdbc事务在插入数据后 下面的代码报错时 数据不会回滚 但是 spring的事务会回滚
- Python3安装Celery模块后执行Celery命令报错
1 Python3安装Celery模块后执行Celery命令报错 pip3 install celery # 安装正常,但是执行celery 命令的时候提示没有_ssl模块什么的 手动在Python解 ...
- 【docker】【redis】2.docker上设置redis集群---Redis Cluster部署【集群服务】【解决在docker中redis启动后,状态为Restarting,日志报错:Configured to not listen anywhere, exiting.问题】【Waiting for the cluster to join...问题】
参考地址:https://www.cnblogs.com/zhoujinyi/p/6477133.html https://www.cnblogs.com/cxbhakim/p/9151720.htm ...
- Hadoop0.20.203.0在关机重启后,namenode启动报错(/dfs/name is in an inconsistent state)
Hadoop0.20.203.0在关机重启后,namenode启动报错: 2011-10-21 05:22:20,504 INFO org.apache.hadoop.hdfs.server.comm ...
- AppiumLibrary库倒入后显示红色,日志报错:ImportError: cannot import name 'InvalidArgumentException'
AppiumLibrary安装后,robotframe worke 倒入后一直显示红色,查看日志报错:ImportError: cannot import name 'InvalidArgumentE ...
- Springboot项目 配置数据库连接属性后,启动项目报错
Springboot项目 配置数据库连接属性后,启动项目报错,错误如下: 错误原因分析: 1.连接信息配置错误 当使用properties为配置文件时,如图所示,上面的 spring.datasour ...
- Sql Server 2008卸载后再次安装一直报错
sql server 2008卸载之后再次安装一直报错问题. 第一:由于上一次的卸载不干净,可参照百度完全卸载sql server2008 的方式 1. 用WindowsInstaller删除所有与S ...
- 配置recovery_min_apply_delay后重启standby节点报错:psql: FATAL: the database system is starting up
环境: pg版本:PostgreSQL 9.4.4 on x86_64 系统版本:CentOS release 6.6 linux内核版本:2.6.32-504.8.1.el6.x86_64 今天测试 ...
随机推荐
- C++之路进阶——codevs1789(最大获利)
1789 最大获利 2006年NOI全国竞赛 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 新的技术正冲击着 ...
- 创建 MIME 类型////////////zzz
用 Apache 创建 MIME 类型 在 Apache 里, MIME 类型和文件扩展名之间的映射是被存放在配置文件 "apache根目录/conf/mime.types" 里的 ...
- AppSettings从数据库读取
/// <summary> /// 提供对配置信息的访问 /// </summary> public static class AppSettings { /// <su ...
- js 简体中文拼音对应表
https://github.com/silaLi/pinyin js 拼音对象,包涵大部分文字
- [Ubuntu] change mouse scrolling between standard and natural
Standard: sudo vi .Xmodmap insert the content as below pointer = Natural: sudo vi .Xmodmap insert th ...
- [MacOS] 终端使用ssh时,中文乱码问题处理
终端显示中文问题处理: vim ~/.inputrc 加入以下代码 set meta-flag on set convert-meta off set input-meta on set output ...
- 分享一个动态生成RDLC报表的类
在实际工作中,当需要进行大批量查询和生成报表的时候,可以使用我写的类. 特点: 无需报表设计器.无需为报表设置数据集 只需要传入查询结果就可以全自动生成报表,传入的对象为Dynamic(目前支持Dat ...
- node 异步编程
node 异步编程 我了解到的node异步编程可分成: 1.回调函数 2.pub/sub模式(发布/订阅模式) 3.promise 4.generator 5.async await 一.直接回调函数 ...
- var ball0=new Ball("executing") 是怎样被执行的?
function Ball(message){ alert(message); }; var ball0=new Ball("executing"); //var ball0=ne ...
- apiCloud又拍云数据库操作经验
1.在数据库表中有个relation字段,表示一对多(对应其他表的多个记录),这个字段比较奇怪,因为实际上这个字段里并未保存实际值.而是保存在对应表的字段中.但是对应表显示出来并没有这个字段.导出数据 ...