日期:2014-04-22 浏览次数:20710 次
...
$includepage=$_GET["includepage"];
include($includepage);
...
$pagelist=array("test1.php","test2.php","test3.php"); //这里规定可进行include的文件
if(isset($_GET["includepage"])) //判断是否有$includepage
{
$includepage=$_GET["includepage"];
foreach($pagelist as $prepage)
{
if($includepage==$prepage) //检查文件是否在允许列表中
{
include($prepage);
$checkfind=true;
break;
}
}
if($checkfind==true){ unset($checkfind); }
else{ die("无效引用页!"); }
}
$id=$_GET["id"];
$query="SELECT * FROM my_table where id='".$id."'"; //很经典的SQL注入漏洞
$result=mysql_query($query);
$text1=$_POST["text1"];
$text2=$_POST["text2"];
$text3=$_POST["text3"];
$fd=fopen("test.php","a");
fwrite($fd,"\r\n$text1&line;$text2&line;$text3");
fclose($fd);
//构造过滤函数
function flt_tags($text)
{
$badwords=array("操你妈","fuck"); //词汇过滤列表
$text=rtrim($text);
foreach($badwords as $badword) //这里进行词汇的过滤
{
if(stristr($text,$badword)==true){ die("错误:你提交的内容含有敏感字眼,请不要提交敏感内容。"); }
}
$text=htmlspecialchars($text); //HTML替换
//这两行把回车替换为
$text=str_replace("\r"," ",$text);
$text=str_replace("\n","",$text);
$text=str_replace("&line;","│",$text); //文本数据库分隔符"&line;"替换为全角的"│"
$text=preg_replace("/\s{ 2 }/"," ",$text); //空格替换
$text=preg_replace("/\t/"," ",$text); //还是空格替换
if(get_magic_quotes_gpc()){ $text=stripslashes($text); } //如果magic_quotes开启,则进行\'的替换
return $text;
}
$text1=$_POST["text1"];
$text2=$_POST["text2"];
$text3=$_POST["text3"];
//过滤全部输入
$text1=flt_tags($text1);
$text2=flt_tags($text2);
$text3=flt_tags($text3);
$fd=fopen("test.php","a");
fwrite($fd,"\r\n$text1&line;$text2&line;$text3");
fclose($fd);
经过一番替换和过滤后,你就可以安全地把数据写入文本或数据库了。
[1] [2] 下一页