Archive | August 2011

Coders headache Part 1: SQL Injection


 
SQL Injection - \S-Q-L-in-'jek-shen\ - Noun
The technique of inputting malicious data into an SQL statement, which would therefore make the vulnerability present on the database layer. Surprisingly, it seems everyone who has recently taken up learning a web development language has to try the technique out on their favorite websites. Luckily for said websites,
this technique isn't at all hard to protect against.

How to fix it?
Well u can use:
$variable= mysql_escape_string(htmlentities(strip_tags(trim($_POST['some_variable']))));

or for better security(int values):

$variable= mysql_escape_string(htmlentities(strip_tags(trim((int)$_POST[‘some_variable’]))));


		
Advertisements