『壹』 php怎么过滤
使用单独一个模块,这个模块负责所有的安全处理。
这个模块被包含在所有公开的 PHP 脚本的最前专端(或者非常靠前的属部分)。
参考下面的脚本security.inc
<?php
switch($_POST['form'])
{
case'login':
$allowed=array();
$allowed[]='form';
$allowed[]='username';
$allowed[]='password';
$sent=array_keys($_POST);
if($allowed==$sent)
{
include'/inc/logic/process.inc';
}
break;
}
?>
『贰』 如何在PHP中成功的过滤危险HTML的代码
//php批量过滤post,get敏感数据
if(get_magic_quotes_gpc()){
$_GET=stripslashes_array($_GET);
$_POST=stripslashes_array($_POST);
}
functionstripslashes_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;
}
//--------------------------
//替换HTML尾标签,为过滤服务
//--------------------------
functionlib_replace_end_tag($str)
{
if(empty($str))returnfalse;
$str=htmlspecialchars($str);
$str=str_replace('/',"",$str);
$str=str_replace("\","",$str);
$str=str_replace(">","",$str);
$str=str_replace("<","",$str);
$str=str_replace("<SCRIPT>","",$str);
$str=str_replace("</SCRIPT>","",$str);
$str=str_replace("<script>","",$str);
$str=str_replace("</script>","",$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("'",chr(39),$str);
$str=str_replace("<br/>",chr(13),$str);
$str=str_replace("''","'",$str);
$str=str_replace("css","'",$str);
$str=str_replace("CSS","'",$str);
return$str;
}
『叁』 PHP 如何过滤特殊字符 如 ◆ )- : 、 、!! / 等
^PHP 中的 preg_replace() 函数可以实现
实例:只匹配中文
<?php
$str="php)!!编程";
echopreg_replace("/[^x{4e00}-x{9fa5}]/iu",'',$str);
?>
『肆』 求php实现多个字符过滤功能
if(preg_match('/(词1|词2|词3)+/', $string)){
return false;
}
『伍』 我做了一个留言板现在想用PHP过滤代码,应该怎么做呀详细思路,谢谢!
主要就是替换留言内容中的一些html敏感标签 像"<",">" 等
还有就是校验内容里面是否有一些sql的关键字 想update 等
其实你可以用编辑框Editor 网上有很多
『陆』 php 小问题大侠们.
echo "<a href='#' onclick=\”window.open('dongtai/login.php','用户注册','width=310 height=300')\"";
你要做什么?
『柒』 php 过滤重复词组 相同关键词测过滤掉
楼上瞎扯淡,人家是要实现过滤重复词组,不是要你对他的代码做解释
function replaceRepeated($words)
{
$arrSrc =explode(" ",$words);
$arrDst =array();
foreach($arrSrc as $key=>$val)
{
if(!in_array($val,$arrDst))$arrDst[] =$val;
}
return join(" ",$arrDst);
}
$str ="大家好 今天天气真好啊 在干么啊 今天天气真好啊 没干什么啊";
echo replaceRepeated($str);//输出大家好 今天天气真好啊 在干么啊 没干什么啊
算法很简单:
将原来的语句用空格分隔到数组,然后定义另外一个数组存放过滤后的词组,在循环式检查当前字符串在第二个数组中是否存在,不存在则存放到第二个数组,最后函数返回第二个数组即可
『捌』 php怎样过滤掉特殊字符啊 ☺
过滤掉特殊字符,可以考虑使用字符串替换的方法,在php中替换字符效率最高也是最简单字符替换函数str_replace函数。
使用方法:str_replace(find,replace,string,count)
参数说明:
find 必需。规定要查找的值。
replace 必需。规定替换 find 中的值的值。
string 必需。规定被搜索的字符串。
count 可选。一个变量,对替换数进行计数。
实例:
str_replace("iwind","kiki","iloveiwind,iwindsaid");
将输出 "i love kiki, kiki said"
当然你也可以采取正则替换的方法,该函数是preg_replace
『玖』 php 如何过滤特殊字符,如 ◆ )- : 、 、!! / 等
可以用 str_replace() 函数统一替换,如:
$string = "测试◆例子♂ 在此 !";
$replace = array('◆','♂',')','=','+','$','¥','-','、','、',':',';','!','!','/');
$string = str_replace($replace, '', $string);
echo $string;