我正试图通过SQL注入来保护我页面上的登录表单.在服务器端,我使用Zend框架(Zend_Db,Zend_Db_Table_Abstract),但其内置的注射预防功能:quote,quoteInto,quoteIdentifier不要让自己的工作做好(据我知道如何使用它们).其他方式mysql_real_escape_string,addslashes似乎根本不起作用......
这就是我正在尝试为防御实现的:
function prevent_from_sql_injection($str) {
if(preg_match('/[\'"]/', $str))
{die('attack1'); exit; }// no quotes
elseif(preg_match('/[\/\\\\]/', $str))
{die('attack2'); exit; }// no slashes
elseif(preg_match('/(and|or|null|not)/i', $str))
{die('attack3'); exit; }// no sqli boolean keywords
elseif(preg_match('/(union|select|from|where)/i', $str))
{die('attack4'); exit; }// no sqli select keywords
elseif(preg_match('/(group|order|having|limit)/i', $str))
{die('attack5'); exit; }// no sqli select keywords
elseif(preg_match('/(into|file|case|LOAD_FILE|DUMPFILE|char|schema|AES_DECRYPT|AES_ENCRYPT)/i', $str))
{die('attack6'); exit; }// no sqli operators
elseif(preg_match('/(--|#|\/\*)/', $str))
{die('attack7'); exit; }// no sqli comments
elseif(preg_match('/(=|&|\|)/', $str))
{die('attack8'); exit; …Run Code Online (Sandbox Code Playgroud)