Задать вопрос
@raxweb

Правильная ли php-функция фильтрации post данных перед записью в mysql?

Отфильтрует ли такая функция все опасные конструкции (XSS, инъекции и подобное)?

Или необходимо еще что-то добавить?

function filter_text_form ($text)
{
$text = strip_tags ($text);//вырезаем HTML теги

$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 ('<', '&lt;', $text);
$text = str_replace ('>', '&gt;', $text);

$text = str_ireplace ('union', '', $text);
$text = str_ireplace ('char', '', $text);
$text = str_ireplace ('get', '', $text);
$text = str_ireplace ('select', '', $text);
$text = str_ireplace ('update', '', $text);
$text = str_ireplace ('group', '', $text);
$text = str_ireplace ('order', '', $text);
$text = str_ireplace ('benchmark', '', $text);
$text = str_ireplace ('connect', '', $text);

connect_db(); $text = mysql_real_escape_string ($text);

return $text;
}
  • Вопрос задан
  • 198 просмотров
Подписаться 2 Простой Комментировать
Решение пользователя Андрей К ответам на вопрос (3)
VladimirAndreev
@VladimirAndreev
php web dev
используйте подготовленные запросы (prepare) и подстановку значений на стороне сервера.

php pdo prepare execute
Ответ написан