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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: