如果我正在清理從表格到mysql表格的代碼,這是否會訣竅?應該/將要輸入的數據將是學校科目和教授的姓氏/名字......關於如何執行此操作的任何其他建議?爲MySQL表格消毒表格數據
/*
Sanitize() function removes any potential threat from the
data submitted. Prevents email injections or any other hacker attempts.
if $remove_nl is true, newline chracters are removed from the input.
*/
function Sanitize($str,$remove_nl=true)
{
$str = $this->StripSlashes($str);
if($remove_nl)
{
$injections = array('/(\n+)/i',
'/(\r+)/i',
'/(\t+)/i',
'/(%0A+)/i',
'/(%0D+)/i',
'/(%08+)/i',
'/(%09+)/i'
);
$str = preg_replace($injections,'',$str);
}
return $str;
}
function StripSlashes($str)
{
if(get_magic_quotes_gpc())
{
$str = stripslashes($str);
}
return $str;
}
會做。我已經對這個問題做了一些研究,但是如果這是正確的方法,我不確定給出上下文(意思是我試圖過濾的數據)。非常感謝John! –