SQL injection in PHP search. Filters keywords to prevent SQL attacks (partial code) ------------------ filters )-------------------------------------------------------------------------------------------------------------
SQL attack prevention => filter keywords (partial code)
------------------------ @ Chenwei -----------------------------
$ K = $ _ REQUEST ['K'];
$ K = addslashes ($ k); // Escape: single quotation marks, double quotation marks, backslash, NULL
$ K = str_replace ('%', '\ %', $ k );
$ K = str_replace ('_', '\ _', $ k );
$ SQL = "select * from users where name like '% $ k % '";
If (! Empty ($ k )){
$ Res = mysql_query ($ SQL, $ con) or die (mysql_error ());
If ($ row = mysql_fetch_assoc ($ res )){
Foreach ($ row as $ k => $ v ){
Echo $ row [$ k]. ':'. $ row [$ v].'
';
}
}
} Else {
Echo '******';
}
Bytes ----------------------------------------------------------------------------------------
Http://www.bkjia.com/PHPjc/817471.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/817471.htmlTechArticle flood to prevent SQL attacks = filter keywords (code partial )--------------------...