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://) ...
随机推荐
- 关于java.io.IOException: HADOOP_HOME or hadoop.home.dir are not set.的问题
报错如下: 300 [main] DEBUG org.apache.hadoop.util.Shell - Failed to detect a valid hadoop home directory ...
- Numpy copy & deep copy
1. '='的赋值方式会带有关联性 >>> import numpy as np >>> a = np.arange(4) >>> b = a & ...
- python入门科普IDE工具和编译环境
应友人之邀,今天来讲述python的一些入门内容.本次讲解的并不是语法或者某个模块. python下载安装 大多数 Linux 发行版在默认安装的情况 ...
- 繁体简体转化_langconv.py
from copy import deepcopyimport re try: import psyco psyco.full()except: pass try: from zh_wiki impo ...
- rabbitmq安装.教程
https://www.cnblogs.com/ericli-ericli/p/5902270.html (rabbitmq安装)https://www.cnblogs.com/iiwen/p/538 ...
- maven install 找不到符号问题
看报错信息是找不到 javax.servlet 包 .这个是tomcat 内的jar包.但是我build path 查看是加了tomcat 的.. 最后在pom.xml 添加依赖 <depend ...
- Sophus链接错误
错误指示如下: CMakeFiles/run_vo.dir/run_vo.cpp.o: In function `main': run_vo.cpp:(.text.startup+0x1086): u ...
- centos下安装配置jetty
下载jdk-8u144-linux-x64.tar.gz # tar -zxvf jdk-8u144-linux-x64.tar.gz # mv jdk1.8.0_144 /usr/java/ # u ...
- ios 内存管理与property copy strong weak assign
- (void)fun{ NSString* str = [[NSString alloc] initWithString:@"string"]; NSLog(@"% ...
- 【NIFI】 实现数据库到数据库之间数据同步
本里需要基础知识:[NIFI] Apache NiFI 安装及简单的使用 数据同步 界面如下: 具体流程: 1.使用ExecuteSQL连接mysql数据库,通过写sql查询所需要的数据 2.nifi ...