MySQLの注入試行を停止するPHP関数を作成しようとしています。私がやっているのは、str_replace()を使ってシンボルを削除し、HTML文字コードで置き換えることです。私の問題は、すべてのコードに&#が含まれていることです。私はそれらの記号をそのコードに置き換えることも望みます。どのように私のようなものにコード を変更せずにこれを行うことができます:PHP記号を文字コードで置き換えてSQLインジェクションを停止する機能
ここ&;&338;#35;32;
私の関数である。
function replaceSymbols($text)
{
$text = str_replace('#', '#', $text);
$text = str_replace('&', '&' $text);
$text = str_replace(';', ';', $text);
$text = str_replace(' ', ' ' $text);
$text = str_replace('!', '!' $text);
$text = str_replace('"', '"' $text);
$text = str_replace('$', '$' $text);
$text = str_replace('%', '%' $text);
$text = str_replace( "'" ''', $text);
$text = str_replace('(', '(' $text);
$text = str_replace(')', ')' $text);
$text = str_replace('*', '*' $text);
$text = str_replace('+', '+', $text);
$text = str_replace(',', ',' $text);
$text = str_replace('-', '-' $text);
$text = str_replace('.', '.' $text);
$text = str_replace('/', '/', $text);
$text = str_replace(':', ':' $text);
$text = str_replace('<', '<' $text);
$text = str_replace('=', '=' $text);
$text = str_replace('>', '>' $text);
$text = str_replace('?', '?', $text);
$text = str_replace('[', '[', $text);
$text = str_replace('\\', '\' $text);
$text = str_replace(']', ']' $text);
$text = str_replace('^', '^' $text);
$text = str_replace('_', '_', $text);
$text = str_replace('`', '`', $text);
$text = str_replace('{', '{' $text);
$text = str_replace('|', '|' $text);
$text = str_replace('}', '}', $text);
$text = str_replace('~', '~', $text);
return $text;
}
これらの文字のほとんどは、SQLインジェクションのリスクを増加させません。 mysql_real_escape_string()関数は、処理が必要なすべての文字を処理します。そしてその関数は、あなたの関数が持たない文字セットをどう扱うかを知っています。 –