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://) ...
随机推荐
- c# sql 复制表后提示列无效解决办法
--CREATE TABLE [dbo].[JinanCount] SELECT * FROM [dbo].[ChengXiangCount] 这条指令错误select * into [dbo]. ...
- c# 关于字典dictionary 按时间排序
上文中说到sortedlist 排序是键排序,不符合项目要求问题,接着使用字典dictionary 对value 为时间按照升序排序,问题解决.中间涉及到linq的使用.还有其他的写法,但发现下边的写 ...
- 24.Mysql高级安装和升级
24.Mysql高级安装和升级24.1 Linux/Unix平台下的安装 24.1.1 安装包比较Linux下的Mysql安装包分为RPM包.二进制包.源码包3种.RPM包优点是安装简单,适合初学者: ...
- linux 发送Post请求 json格式
curl -H "Content-type: application/json" -X POST -d '{"text":"总体来说很不错,环境挺好的 ...
- Android开发之SharedPreferences的封装
对于大部分初学者来说,如果想利用SharedPreferences进行数据存储的话大部分人(包括本人)应该会这样: 存储: SharedPreferences sharedPreferences = ...
- Android开发之自定义Dialog简单实现
本文着重研究了自定义对话框,通过一下步骤即可清晰的理解原理,通过更改界面设置和style类型,可以应用在各种各样适合自己的App中. 首先来看一下效果图: 首先是activity的界面 点击了上述图片 ...
- 关于nodejs 假设httpserver,会发现一次网页打开,服务端会响应两次的问题;
转自:http://cnodejs.org/topic/518772806d38277306804020 每个页面默认都会再发一个de style="line-height: 21px; p ...
- 大神你好,可以帮我P张图吗?
韩国版的求大神帮我P张图,看得有点下巴脱臼啊!哈哈哈哈哈哈哈~ 感觉照片拍得很尴尬,请大神P得更有动感 拍了跳跃照片,但内衣露出来一点,能帮忙去掉吗 不喜欢没穿制服的样子,请帮忙加上制服 希望背景 ...
- jvm 基础
1. JDK 包含 java 程序设计语言,JVM, Java API类库. java 开发最小环境 2. JRE : Java API类库中java se API 子集和java 虚拟机(HotSp ...
- this高级应用 - 域隔离
在js环境中,this有很多指向(window.dom.object等),巧妙的利用this,可以有效的防止变量或方法被外界污染,保证代码健壮性,实例如下. demo: <!DOCTYPE ht ...