Home  >  Article  >  Backend Development  >  Simple PHP anti-injection content filtering method_PHP tutorial

Simple PHP anti-injection content filtering method_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:48:021113browse

Content filtering is mainly to prevent some security injections or cross-domain operations. Let’s take a look at some simple anti-injection content filtering program codes that I compiled. I hope the article will be helpful to all students.

Method 1, filter some useless content

The filtering of useless information is strict, and useful information may not be entered. You can find other filtering methods on the Internet:

The code is as follows
 代码如下 复制代码

function checkHtml($data){
  $ret  = preg_match("/['.,:;*?~`!@#$%^&+=)(<>{}]|]|[|/||"||/",$data);
  if ($ret == 1) {
    return false; exit;
  } else {
    return true;
  }
}

Copy code

 代码如下 复制代码


function uh($str)
{
$farr = array(
"/s+/", //过滤多余的空白
"/<(/?)(scripti?framestylehtmlbodytitlelinkmeta?%)([^>]*?)>/isU", //过滤