How to protect against SQL Injection

เจออยู่นานแล้วคิดว่าเก็บเอามาแปะบล๊อกไว้ดีกว่า เดี๋ยวจะลืมซะก่อน Function แหล่มๆ ไว้กัน SQL Injection นะครับ


GET Method 
function mysqlesc($input){
$input = str_ireplace('\'', '', $input);
$input = str_ireplace('"', '', $input);
$input = str_ireplace('UNION', '', $input);
$input = str_ireplace('--', '', $input);
$input = str_ireplace('/**/', '', $input);
$input = str_ireplace('/*', '', $input);
$input = trim($input);
return $input;
}

POST Method 
function mysqlesc($input){
$input = mysql_real_escape_string($input);
return $input;
}

Ref : http://santoshdudhade.blogspot.com/2011_11_01_archive.html

บทความเพิ่มเติม

Ref : http://www.stephack.com/coding/how-to-bypass-function-sqli-check.html how to bypass function SQLi check ?

ที่มา : http://icheernoom.blogspot.com/2011/12/how-to-protect-against-sql-injection.html