您是否考虑过将常用安全函数应用于复杂场景,以提升系统安全性?
- 内容介绍
- 文章标签
- 相关推荐
本文共计524个文字,预计阅读时间需要3分钟。
php常用项目安全函数 + // 文本编辑器标签过滤(HTMLPurifier插件)function removeXSS($data) { require_once './HtmlPurifier/HTMLPurifier.auto.php'; $clean_xss_config=HTMLPurifier_Config::createDefault();}
//富文本编辑器标签过滤(htmlpurifier插件)
function removeXSS($data)
{
require_once './HtmlPurifier/HTMLPurifier.auto.php';
$_clean_xss_config = HTMLPurifier_Config::createDefault();
$_clean_xss_config->set('Core.Encoding', 'UTF-8');
// 设置保留的标签
$_clean_xss_config->set('HTML.Allowed','div,b,strong,i,em,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]');
$_clean_xss_config->set('CSS.AllowedProperties', 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align');
$_clean_xss_config->set('HTML.TargetBlank', TRUE);
$_clean_xss_obj = new HTMLPurifier($_clean_xss_config);
// 执行过滤
return $_clean_xss_obj->purify($data);
}
/**
* 登录原地址跳转过滤函数
* redirect('home/login?from='__SELF__,0,'正在跳转'); 通过I('get.from')获取原地址,但是如果from被恶意手动输入外部网址,则登录就会跳转到外部网站,所以需要做下面的地址过滤 from=后面的url地址
* @param [type] $url [description]
* @return [type] [description]
*/
function gt($url){
// 如果存在开头
if(preg_match("/^http:\/\//i", $url)){
// 白名单
if(preg_match("/^http:\/\/(localhost)|(www.baidu.com)/i")){
return $url;
}else{
return 'home/index/index';
}
}else{
return $url;
}
}
/**************onethink加解密码方法********************
使用demo 加密cookie
setcookie('user',think_encrypt(serialize($user_login,C('KEY')),time()+3600,"/"))
*/
/**
* 系统加密方法
* @param string $data 要加密的字符串
* @param string $key 加密密钥
* @param int $expire 过期时间 单位 秒
* @return string
* @author 麦当苗儿
本文共计524个文字,预计阅读时间需要3分钟。
php常用项目安全函数 + // 文本编辑器标签过滤(HTMLPurifier插件)function removeXSS($data) { require_once './HtmlPurifier/HTMLPurifier.auto.php'; $clean_xss_config=HTMLPurifier_Config::createDefault();}
//富文本编辑器标签过滤(htmlpurifier插件)
function removeXSS($data)
{
require_once './HtmlPurifier/HTMLPurifier.auto.php';
$_clean_xss_config = HTMLPurifier_Config::createDefault();
$_clean_xss_config->set('Core.Encoding', 'UTF-8');
// 设置保留的标签
$_clean_xss_config->set('HTML.Allowed','div,b,strong,i,em,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]');
$_clean_xss_config->set('CSS.AllowedProperties', 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align');
$_clean_xss_config->set('HTML.TargetBlank', TRUE);
$_clean_xss_obj = new HTMLPurifier($_clean_xss_config);
// 执行过滤
return $_clean_xss_obj->purify($data);
}
/**
* 登录原地址跳转过滤函数
* redirect('home/login?from='__SELF__,0,'正在跳转'); 通过I('get.from')获取原地址,但是如果from被恶意手动输入外部网址,则登录就会跳转到外部网站,所以需要做下面的地址过滤 from=后面的url地址
* @param [type] $url [description]
* @return [type] [description]
*/
function gt($url){
// 如果存在开头
if(preg_match("/^http:\/\//i", $url)){
// 白名单
if(preg_match("/^http:\/\/(localhost)|(www.baidu.com)/i")){
return $url;
}else{
return 'home/index/index';
}
}else{
return $url;
}
}
/**************onethink加解密码方法********************
使用demo 加密cookie
setcookie('user',think_encrypt(serialize($user_login,C('KEY')),time()+3600,"/"))
*/
/**
* 系统加密方法
* @param string $data 要加密的字符串
* @param string $key 加密密钥
* @param int $expire 过期时间 单位 秒
* @return string
* @author 麦当苗儿

