我知道大多数人会对此皱眉,但在我了解 PDO 语句和转义字符串之前,我不确定我应该如何防止 mysql 注入。
我创建了一个函数,它接受文本并通过过滤器运行它。我想知道它是否真的会阻止sql注入或者他们是否可以绕过它?我当时的目标是让用户能够输入文本并能够完全按照他们输入的方式显示。
除此之外,我还小心翼翼地确保用户对数据库的权限不超过所需权限。我是否使用他们的输入来更新或插入新行等。但鉴于我没有它仍然可以工作吗?:
function filterInput($textToFilter)
{
if ($textToFilter != null)
{
//a = a
//e = e
//i = i
//o = o
//u = u
//A = A
//E = E
//I = I
//O = O
//U = U
$textToFilter = str_ireplace('insert','insert',$textToFilter);
$textToFilter = str_ireplace('select','select',$textToFilter);
$textToFilter = str_ireplace('values','values',$textToFilter);
$textToFilter = str_ireplace('where','where',$textToFilter);
$textToFilter = str_ireplace('order','order',$textToFilter);
$textToFilter = str_ireplace('into','into',$textToFilter);
$textToFilter = str_ireplace('drop','drop',$textToFilter);
$textToFilter = str_ireplace('delete','delete',$textToFilter);
$textToFilter = str_ireplace('update','update',$textToFilter);
$textToFilter = str_ireplace('set','set',$textToFilter);
$textToFilter = str_ireplace('flush','flush',$textToFilter);
$textToFilter = str_ireplace("'","'",$textToFilter);
$textToFilter = str_ireplace('"',""",$textToFilter);
$textToFilter = str_ireplace(';',";",$textToFilter);
$textToFilter = str_ireplace('>',"›",$textToFilter);
$textToFilter = str_ireplace('<',"‹",$textToFilter);
$textToFilter = nl2br($textToFilter);
$filterInputOutput = $textToFilter;
return $filterInputOutput;
}
}