search
Homephp教程PHP源码php过滤恶意字符

php过滤恶意字符

May 26, 2016 am 08:19 AM

php过滤恶意字符

//php 批量过滤post,get敏感数据
  
if (get_magic_quotes_gpc()) {
  
$_GET = stripslashes_array($_GET);
  
$_POST = stripslashes_array($_POST);
  
}
  
function stripslashes_array(&$array) {
  
while(list($key,$var) = each($array)) {
  
if ($key != 'argc' && $key != 'argv' && (strtoupper($key) != $key || ''.intval($key) == "$key")) {
  
if (is_string($var)) {
  
$array[$key] = stripslashes($var);
  
}
  
if (is_array($var)) {
  
$array[$key] = stripslashes_array($var);
  
}
  
}
  
}
  
return $array;
  
}
  
//过滤
  
function htmlencode($str){
  
if(empty($str)) return;
  
if($str=="") return $str;
  
$str=trim($str);
  
$str=str_replace("&","&",$str);
  
$str=str_replace(">",">",$str);
  
$str=str_replace("=strlen($block) && preg_match("/$block/i", $string))
  
{
  
$blist[] = $block;
  
}
  
}
  
//判断有没有过滤内容在数组里
  
if (!empty($blist))
  
{
  
return array_unique($blist);
  
}
  
return false;
  
}
  
//--------------------------
  
// 替换HTML尾标签,为过滤服务
  
//--------------------------
  
function lib_replace_end_tag($str)
  
{
  
if (empty($str)) return false;
  
$str = htmlspecialchars($str);
  
$str = str_replace( '/', "", $str);
 
$str = str_replace("\\", "", $str);
  
$str = str_replace(">", "", $str);
  
$str = str_replace("<", "", $str);
  
$str = str_replace("", "", $str);
  
$str = str_replace("", "", $str);
  
$str=str_replace("select","select",$str);
  
$str=str_replace("join","join",$str);
  
$str=str_replace("union","union",$str);
  
$str=str_replace("where","where",$str);
  
$str=str_replace("insert","insert",$str);
  
$str=str_replace("delete","delete",$str);
  
$str=str_replace("update","update",$str);
  
$str=str_replace("like","like",$str);
  
$str=str_replace("drop","drop",$str);
  
$str=str_replace("create","create",$str);
  
$str=str_replace("modify","modify",$str);
  
$str=str_replace("rename","rename",$str);
  
$str=str_replace("alter","alter",$str);
  
$str=str_replace("cas","cast",$str);
  
$str=str_replace("&","&",$str);
  
$str=str_replace(">",">",$str);
  
$str=str_replace("<","<",$str);
  
$str=str_replace(" ",chr(32),$str);
  
$str=str_replace(" ",chr(9),$str);
  
$str=str_replace(" ",chr(9),$str);
  
$str=str_replace("&",chr(34),$str);
  
$str=str_replace("&#39;",chr(39),$str);
  
$str=str_replace("
  
",chr(13),$str);
  
$str=str_replace("&#39;&#39;","&#39;",$str);
  
$str=str_replace("css","&#39;",$str);
  
$str=str_replace("CSS","&#39;",$str);
  
return $str;
  
//HTML标签,可以作为扩展过滤
  

  
}

                   

以上就是php过滤恶意字符的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.