security.php
<?php
/**
*
*/
class Security
{
public function csrf_verify()
{
if(count($_POST) == 0)
{
return '';
}
if(!isset($_POST[$tokenname])
OR !isset($_COOKIE[$tokenname]))
{
return '';
}
unset($_POST[$tokenname]);
unset($_COOKIE[$tokenname]);
} public function csrf_set_cookie()
{
$expire = time()+$this->expire;
$secure_cookie = 1;
if($secure_cookie)
{
$req = isset($_SERVER['HTTPS'])?$_SERVER['HTTPS']:FALSE;
}
setcookie($cookiename, $hash, $expire, $cookiepath, $cookedomain, $secure_cookie);
return $this;
} public function xss_clean($str, $is_image = FALSE)
{
if(is_array($str))
{
while (list($key) = each($str))
{
$str[$key] = '';
}
return $str;
} $str = rawurldecode($str);
$str = preg_replace_callback('/[a-z]+=([\'\"]).*?\\1/si', array($this, '_conver_attribute', $str);
$str = preg_replace('/<\w+.*?(?=>|<|$)/si', array($this, '_decode_entity', $str); if(strpos($str, "\t") !== FALSE)
{
$str = str_replace("\t", ' ', $str);
} if($is_image === TRUE)
{
$str = preg_replace('/<\?(php)/i', '<?\\1', $str);
} do
{
$original = $str;
if(preg_match("/<a/i", $str))
{
$str = preg_replace_callback("##si", array($this, '_js_link_removal'), $str);
}
}
while ($original != $str);
unset($original);
} public function xss_hash()
{
mt_srand();
$xss_hash = md5(time() + mt_rand(0, 199999999999999));
return $xss_hash;
} public function entity_decode($str, $charset='UTF-8')
{
if (stristr($str, '&') === FALSE) {
return $str;
} $str = html_entity_decode($str, ENT_COMPAT, $charset);
$str = preg_replace('~&#X(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str);
return stripslashes(preg_replace('~&#([0-9]{2-4})~e', 'chr(\\1)', $str));
}
}
security.php的更多相关文章
- Security Policy:行级安全(Row-Level Security)
行级安全RLS(Row-Level Security)是在数据行级别上控制用户的访问,控制用户只能访问数据库表的特定数据行.断言是逻辑表达式,在SQL Server 2016中,RLS是基于安全断言( ...
- Content Security Policy 入门教程
阮一峰文章:Content Security Policy 入门教程
- Spring Security OAuth2 开发指南
官方原文:http://projects.spring.io/spring-security-oauth/docs/oauth2.html 翻译及修改补充:Alex Liao. 转载请注明来源:htt ...
- WCF : 修复 Security settings for this service require Windows Authentication but it is not enabled for the IIS application that hosts this service 问题
摘要 : 最近遇到了一个奇怪的 WCF 安全配置问题, WCF Service 上面配置了Windows Authentication. IIS上也启用了 Windows Authentication ...
- .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数
.Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...
- SimpleSSO:使用Microsoft.Owin.Security.OAuth搭建OAuth2.0授权服务端
目录 前言 OAuth2.0简介 授权模式 (SimpleSSO示例) 使用Microsoft.Owin.Security.SimpleSSO模拟OpenID认证 通过authorization co ...
- spring mvc 和spring security配置 spring-servlet.xml和spring-security.xml设置
spring-servlet.xml配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmln ...
- spring mvc 和spring security配置 web.xml设置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmln ...
- 无法解决“Microsoft.SharePoint.Security, Version=15.0.0.0,”与“Microsoft.SharePoint.Security, Version=14.0.0.0”之间的冲突
VisualStudio 2013创建控制台项目,.NetFramework选为4.5.生成目标平台:x64.然后添加对Microsoft.SharePoint.dll的引用. 生成项目时," ...
- iOS App 不支持http协议 App Transport Security has blocked a cleartext HTTP (http://)
目前iOS已经不支持http协议了,不过可以通过info.plist设置允许 App Transport Security has blocked a cleartext HTTP (http://) ...
随机推荐
- Linux ulimit
一.简介 二.语法 三.其他 1)linux下进程的进程最大数.最大线程数.进程打开的文件数和ulimit命令修改硬件资源限制 http://blog.csdn.net/gatieme/art ...
- Activity和Intent
- RDMA的原理、传输与Verbs
RDMA的原理.传输与Verbs RDMA最早专属于infiniband架构.在网络融合的大趋势下出现的RoCE,使高速.超低延时.极低cpu使用率的RDMA得以部署在目前使用最广泛的以太网上. ...
- UVA-1364.Knights of the Round Table 无向图BCC
题目链接:https://vjudge.net/problem/UVA-1364 题意:有n个人参加会议,互相憎恨的人不能坐在相邻的位置,并且每个会议参加的人数必须是奇数,求有多少个人不能参加任何一个 ...
- Laravel自定义Api接口全局异常处理
在做API时,需要对一些异常进行全局处理,比如添加用户执行失败时,需要返回错误信息 // 添加用户 www.bcty365.com $result = User::add($user); if(emp ...
- How to Set Ckeditor ReadOnly Mode
CKEditor API makes it possible to render the editor content read-only (and thus impossible for the u ...
- 【Redis】Redis cluster集群搭建
Redis集群基本介绍 Redis 集群是一个可以在多个 Redis 节点之间进行数据共享的设施installation. Redis 集群不支持那些需要同时处理多个键的 Redis 命令, 因为执行 ...
- spring学习 十五 spring的自动注入
一 :在 Spring 配置文件中对象名和 ref=”id” ,id 名相同使用自动注入,可以不配置<property/>,对应的注解@Autowired的作用 二: 两种配置办法 (1 ...
- Windows AD域管理软件是什么?
Windows AD域管理软件是什么? ADManager Plus是一个简单易用的Windows AD域管理工具,帮助域管理员简化日常的管理工作.通过直观友好的操作界面,可以执行复杂的管理操作,比如 ...
- vue-cli引入jquery方法
方法一: 一,在package.json里加入, dependencies:{ ”jquery“:”^2.3.4“ } 二,在webpack.base.conf.js里加入 const webpack ...