php验证所有提交内容是否包括有非法字符(防止SQL注入攻击)
<?php
function checkIllegalWord(){
//定义不允许提交的SQL命令及关键字
$words=array();
$words[] = "add";
$words[] = "count";
$words[] = "create";
$words[] = "drop";
$words[] = "from";
$words[] = "grant";
$words[] = "insert";
$words[] = "select";
$words[] = "truncate";
$words[] = "update";
$words[] = "use";
$words[] = "--";
//
foreach($_REQUEST as $strGot){
$strGot = strtolower($strGot);
foreach($words as $word){
if(strstr($strGot,$word)){
echo "danger character !";
exit;
}//end if
}//end foreach2
}//end foreach1
}
checkIllegalWord();
echo $_POST['username'];
?>
<form id="form1" name="form1" method="post" action="?">
<input name="username" type="text" id="username" value="" />
<input type="submit" name="Submit" value="提交" />
</form>
上一篇:PHP随机产生字符串
下一篇:php-Mysql数据库用mysqli()与mysqli_connect()连接测试
讨论数量:0