View Single Post
Old 12-08-2007, 07:16 PM   #9 (permalink)
Village Idiot
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Always single quote your variables, otherwise injection is easy (even if cleaned). For instance
PHP Code:
 $var "1 OR 1=1 --";
$query mysql_query("SELECT * FROM `users` WHERE `id` = $var");
//the query is now
$query mysql_query("SELECT * FROM `users` WHERE `id` = 1 OR 1=1 --"); 
Even if you clean that, the injection will work, now if you change it to
PHP Code:
 $query mysql_query("SELECT * FROM `users` WHERE `id` = '$var'"); 
The hacker would have to put a single quote to put a command in, the single quote would be escaped. Turning the query into
PHP Code:
 $query mysql_query("SELECT * FROM `users` WHERE `id` = '1 OR 1=1 --'"); 
All types must be quoted, mysql knows how to deal with it.
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
SOCK (12-08-2007)