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://) ...
随机推荐
- vs的【warning C4996:'fopen': This function or variable may be unsafe】解决方案
编译警告:warning C4996 与 Security Enhancements in the CRT 将过去的工程用VS2005打开的时候.你有可能会遇到一大堆的警告:warning C4996 ...
- C++中string类
https://blog.csdn.net/sinat_36184075/article/details/54836053 https://blog.csdn.net/fdqw_sph/article ...
- 向kafka批量发送已存在的txt文件
需要利用kafka发送txt或log文件,有两种方式:1.自己写程序:2.利用kafka自带脚本. 自己写程序: import org.apache.kafka.clients.producer.Ka ...
- appache压力测试
apache自带压力工具测试说明: Usage: ab [options] [http[s]://]hostname[:port]/pathOptions are: -n requests Numbe ...
- 显示实现接口的好处c#比java好的地方
所谓Go语言式的接口,就是不用显示声明类型T实现了接口I,只要类型T的公开方法完全满足接口I的要求,就可以把类型T的对象用在需要接口I的地方.这种做法的学名叫做Structural Typing,有人 ...
- python文件读取操作、序列化
1.对文件进行读写操作时,先建立文件句柄 f = open("test.txt","r",encoding="UTF-8") 其中,r为文件 ...
- Java虚拟机的相关笔记
1.垃圾GC回收事件Minor GC(只清除新生代),Full GC(清除新生代和老年代),Major GC(清除新生.老年代和持久代). 2.堆分为新生代.老年代和持久代,持久代一般存放静态文件. ...
- 2017/2/5:oracle数据库的三大文件
oracle的三大文件: 一:控制文件:控制文件是一个小型的二进制文件,可以记录数据库的物理结构.包括: * 数据库名称 * 数据文件和日志文件的名称和位置 * 数据库创建的时 ...
- Selenium实战总结(webwiew下拉框定位)
基于常见的两种下拉框的展示形式: 1.点击弹出下拉框: 2.鼠标移动弹出下拉框(move_to_element) 实例一[鼠标点击弹出的下拉框]: e.g百度首页的设置--高级搜索--时间: 导包: ...
- liunx基础命令
linux的简单介绍 linux是一款免费使用和自由传播的内似于unix的操作系统软件,是一个基于POSI和unix的多用户,多任务,支持多线程和多CPU的一种操作系统.主要用于服务器,特别是网络服务 ...