...
$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);
经过一番替换和过滤后,你就可以安全地把数据写入文本或数据库了。
新闻热点
疑难解答