Yii-CHtmlPurifier- 净化器的使用(yii过滤不良代码)
1. 在控制器中使用:
public function actionCreate()
{
$model=new News; $purifier = new CHtmlPurifier();
$purifier->options = array(
'URI.AllowedSchemes'=>array(
'http' => true,
'https' => true,
),
'HTML.Allowed'=>'div',
); if(isset($_POST['News']))
{
$model->attributes=$_POST['News'];
$model->attributes['content'] = $purifier->purify($model->attributes['content']);
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
}
2. 在模型中的使用:
protected function beforeSave()
{
$purifier = new CHtmlPurifier();
$purifier->options = array(
'URI.AllowedSchemes'=>array(
'http' => true,
'https' => true,
),
'HTML.Allowed'=>'div',
); if(parent::beforeSave()){
if($this->isNewRecord){
$this->create_data = date('y-m-d H:m:s');
$this->content = $purifier->purify($this->content);
}
return true;
}else{
return false;
}
}
3. 在过滤器中的使用:
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
'purifier + create', //载入插入页面时进行些过滤操作
);
} public function filterPurifier($filterChain){
$purifier = new CHtmlPurifier();
$purifier->options = array(
'URI.AllowedSchemes'=>array(
'http' => true,
'https' => true,
),
'HTML.Allowed'=>'div',
);
if(isset($_POST['news']){
$_POST['news']['content'] = $purify($_POST['news']['content']);
}
$filterChain->run();
}
4. 在视图中的使用:
<?php $this->beginWidget('CHtmlPurifier'); ?>
...display user-entered content here...
<?php $this->endWidget(); ?>
Yii-CHtmlPurifier- 净化器的使用(yii过滤不良代码)的更多相关文章
- YII框架的部署 通过YII脚手架程序创建应用程序系统
1,把YII框架里面的framework复制粘贴到nginx目录下 2,创建一个商城系统: 1)修改环境变量 制定php.exe的目录 2)C:\Users\Administrator>cd C ...
- 简单分析下用yii2的yii\helpers\Html类和yii.js实现的post请求
yii2提供了很多帮助类,比如Html.Url.Json等,可以很方便的实现一些功能,下面简单说下这个Html.用yii2写view时时经常会用到它,今天在改写一个页面时又用到了它.它比较好用的地方就 ...
- php 安全过滤函数代码
php 安全过滤函数代码,防止用户恶意输入内容. //安全过滤输入[jb] function check_str($string, $isurl = false) { $string = preg_r ...
- 取缔Chrome装载电脑管家的广告过滤脚本代码
今天Chrome调试脚本.加载在下面的脚本中找到的内容: /* 电脑管家chrome 广告过滤 */ var GJAD_CS = { elemhideElt : null, setElemhideCS ...
- c# 过滤HTML代码 源代码,案例 下载
#region 过滤HTML代码 //替换掉html字符,只显示文字信息. public string replaceHtmlCode(string Htmlstring) { Htmlstring ...
- 项目git commit时卡主不良代码:husky让Git检查代码规范化工作
看完 <前端规范之Git工作流规范(Husky + Commitlint + Lint-staged) https://www.cnblogs.com/Yellow-ice/p/15349873 ...
- yii过滤xss代码,防止sql注入
作者:白狼 出处:www.manks.top/article/yii2_filter_xss_code_or_safe_to_database 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明 ...
- YII学习,初体验 ,对YII的一些理解.
先说点没用的: 不会选择,选择后不坚持,不断的选择.这是人生中的一个死循环,前两一直迷茫.觉得自己前进方向很不明朗.想去学的东西有很多.想学好YII,想学PYTHON 想学学hadoop什么的,又想研 ...
- YIi配置debug工具、yii配置gii工具
$config['bootstrap'][] = 'debug';$config['modules']['debug'] = [ 'class'=>'yii\debug\Module', 'al ...
随机推荐
- 好使-利用python 下paramiko模块无密码登录
[root@salt-minion02 paramiko]# vim baoleiji4.py # -*- coding:utf-8 -*-import paramikoprivate_key = p ...
- Microsoft.Crm.Setup.SrsDataConector.RegisterServerAction 操作失败 Requested value 'Geo' was not found 的解决方法
error installing ssrs data connector on sql server for dynamics crm 2011 I think the post title says ...
- 织梦dedecms模板制作时,循环递增autoindex使用方法整理
文章转载:http://www.maihui123.com/dedecms/2012051964.html 织梦dedecms模板制作时,我们需要每循环一次,变量加一,这是就需要使用到autoinde ...
- WinRAR打包时不包含文件夹本身,只打包文件夹里的文件和目录
加上-ep1 参数即可. rar u -m3 -s -r -o+ -ep1 -x*.zip client_zmv9.zip ".\client_zmv9\*"
- 设计模式初学者笔记:Builder模式
[作者:byeyear Email:byeyear@hotmail.com 首发:cnblogs 转载请注明] 在本文的开头,先森森的鄙视下自己……将Builder模式反反复复读了七 ...
- 【Spring-AOP-学习笔记-6】@AfterThrowing增强处理简单示例
项目结构 业务代码 @Component("hello") public class HelloImpl implements Hello { // 定义一个简单方法,模拟 ...
- jackson快速实现对象与json之间的转换
Maven依赖: <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <arti ...
- maven学习(6)-Maven依赖范围
一.maven依赖范围: classpath 分为三种:编译classpath , 测试classpath , 运行classpath Scope 选项如下: Compile:编译依赖范围.默认就是c ...
- 学习笔记之Visual Studio Team Services
VSTS and TFS Documentation | Microsoft Docs https://docs.microsoft.com/en-us/vsts/index?view=vsts#pi ...
- 绕过限制,在PC上调试微信手机页面
场景 假设一个手机页面,开发者对其做了限制,导致只能在微信客户端中打开.而众所周知手机上非常不利于调试页面,所以需要能在电脑上打开并进行调试.这里针对常见的三种页面做一下分析,一一绕过其限制,(当然不 ...