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://) ...
随机推荐
- CSS学习总结2:CSS框模型
1.CSS框模型概述 CSS框模型规定了元素框处理元素内容.内边框.边框和外边框的方式. 元素框的最内部分是实际的内容,直接包围内容的是内边距.内边距呈现了元素的背景.内边距的边缘是边框.边框以外是外 ...
- Android开发颜色大全
<!-- dialog背景颜色 --> <color name=</color> <color name="white">#FFFFFF& ...
- C# 判断ip地址是否正确
最后要用一方法判断ip地址是否正确,直接用.Net现成的类,方法如下: string ipStr="192.168.222.333"; IPAddress ip; if(IPAdd ...
- Win32消息循环机制等【转载】http://blog.csdn.net/u013777351/article/details/49522219
Dos的过程驱动与Windows的事件驱动 在讲本程序的消息循环之前,我想先谈一下Dos与Windows驱动机制的区别: DOS程序主要使用顺序的,过程驱动的程序设计方法.顺序的,过程驱动的程序有一个 ...
- DtCMS 在IIS7.0 下之伪静态
1)首先新建一个应用程序池,名称任意,比如:nettest,托管管道模式先暂时设置为集成模式,等下面的一系列设置完成之后再设置成经典模式: 2)部署好站点,并将此站点的应用程序池设置为nettest; ...
- python自学开始
95年工科女一枚 java工程师算不上,只能说从事java开发相关的工作,由于对Python有着极其浓厚的兴趣,一周时间了解大概之后,决定从今天开始见缝插针自学Python,为了防止本人三天打鱼两天晒 ...
- C语言中内存分布及程序运行中(BSS段、数据段、代码段、堆栈)
BSS段:(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域.BSS是英文Block Started by Symbol的简称.BSS段属于静态内存分配. 数据段 : ...
- Python.URLs
1. The Future of Asynchronous IO in Python https://medium.com/@paulcolomiets/the-future-of-asynchron ...
- 洛谷4782 【模板】2-SAT 问题
原题链接 \(2-SAT\)模板 #include<cstdio> using namespace std; const int N = 2e6 + 10; int fi[N], di[N ...
- selinux 导致ftp文件夹出错~
关掉selinux #setenforce 0