...
$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("http://s{ 2 }/"," ",$text); //空格替換
$text=preg_replace("http://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);
經過一番替換和過濾后,你就可以安全地把數據寫入文本或數據庫了。
新聞熱點
疑難解答