SQL Injection is an attack technique used to exploit applications that construct SQL statements from user-supplied input. When successful, the attacker is able to change the logic of SQL statements executed against the database. This can allow an attacker to not only steal data from your database, but also modify and delete it. It's one of the more popular application layer hacking techniques that is used in the wild today. In this tutorial will teach you how to create your own function to protect your website against sql injection.
SQL injections based on poorly filtered strings are caused by user input that is not filtered for nonperformance characters. This means that a user can input a string that can be passed on as an SQL statement, resulting in database manipulation. The following examples illustrate a vulnerable code:
$password = $_POST['password'];
$query = mysql_query("SELECT password FROM users WHERE password = '". $password . "'");
The query above is an SQL call to SELECT the password from the users database, If the user input for the password is ' OR 1 = 1 /* will result in the query being extended with an OR statement as 1 does equal 1, thus the query will return TRUE, resulting in a positive login.
We create a function that will sanitize and escaped bad characters in the sql query and used the following useful php function. let's call it "safeSQL".
stripslashes() - If magic_quotes_gpc is enabled lets stripslashes so the string will not be double escaped.
addslashes() - If magic_quotes_gpc is not enabled lets add addslashes.
mysql_real_escape_string() - Final phase lets escape all special characters in the string.
Easy stuff, here is the full function:
<?php
function safeSQL($string)
{
if(get_magic_quotes_gpc()) // If magic_quotes_gpc is enabled.
{
$string = stripslashes($string);
}
elseif(!get_magic_quotes_gpc())
{
$string = addslashes($string);
}
$string = mysql_real_escape_string($string);
return $string; // Returns the safe string.
}
?>
Now to use this function, just wrap the function around the data, example:
<?php
$password = safeSQL($_POST['password']);
?>
Any Suggestion? Add a comment below. Thanks!
Fantastic blog. Great.
I really liked your article.Really thank you! Awesome.
Major thankies for the post.Thanks Again. Keep writing.
Hey, thanks for the blog post.Really looking forward to read more. Cool.
Fantastic blog post.Thanks Again. Really Cool.
Thanks for the blog article.Thanks Again. Much obliged.
I truly appreciate this post.Much thanks again. Really Great.
Muchos Gracias for your article.Really looking forward to read more. Much obliged.
Major thankies for the article post.Much thanks again.
Fantastic post.Thanks Again. Much obliged.
Im obliged for the article post.Thanks Again. Really Cool.
I cannot thank you enough for the article.Much thanks again. Keep writing.
Very good blog.Thanks Again. Fantastic.
Thanks a lot for the blog.Thanks Again. Cool.
Major thankies for the blog.Really looking forward to read more. Awesome.
Major thanks for the blog post.Much thanks again. Want more.
Really enjoyed this blog post. Will read on...
Say, you got a nice blog post.Really thank you! Awesome.
Thanks again for the post.Much thanks again. Cool.
Major thankies for the blog.Much thanks again. Keep writing.
Awesome article post.Really thank you!
Enjoyed every bit of your article post.Thanks Again. Awesome.
nice thoughts..
Say, you got a nice post.Really thank you! Will read on...
Major thankies for the blog post. Keep writing.
Really enjoyed this post.Much thanks again. Will read on...
I really liked your post.Much thanks again. Great.
A big thank you for your post.Much thanks again. Great.
useful..
A round of applause for your article.Really looking forward to read more. Awesome.
This is one awesome blog post.Really thank you! Keep writing.
Hey, thanks for the blog.Thanks Again. Fantastic.
Very good article. Great.
Major thankies for the article post.Really thank you!
I think this is a real great post.Thanks Again. Fantastic.
Thanks for the blog article.Really looking forward to read more. Cool.
I really liked your blog post.Really looking forward to read more. Really Great.
Really enjoyed this post.Much thanks again. Want more.
Im thankful for the blog post.Much thanks again. Much obliged.
A big thank you for your blog article.Really looking forward to read more. Great.
Say, you got a nice blog article.Much thanks again. Fantastic.
I think this is a real great blog article. Cool.
I think this is a real great blog.Much thanks again. Cool.
Thanks so much for the article.Much thanks again. Much obliged.
Awesome article.Much thanks again. Really Cool.
I value the post.Really looking forward to read more. Cool.
Appreciate you sharing, great article.Really thank you! Keep writing.
Muchos Gracias for your blog post.Really looking forward to read more. Great.
I think this is a real great article.Really thank you! Much obliged.
I really enjoy the post.Really looking forward to read more. Really Cool.
I cannot thank you enough for the article post.Thanks Again. Awesome.
Really informative article.Really looking forward to read more. Keep writing.
I cannot thank you enough for the post.Really thank you! Want more.
Fantastic article post.Really looking forward to read more. Fantastic.
Very good blog article.Much thanks again. Really Cool.
I value the blog post.Really thank you! Really Cool.
Wow, great post.Thanks Again. Will read on...
Really enjoyed this blog article.Really looking forward to read more. Much obliged.
A big thank you for your blog post.Really looking forward to read more. Cool.
Appreciate you sharing, great article post.Much thanks again. Great.
I truly appreciate this article.Really looking forward to read more. Keep writing.
This is one awesome blog article.Thanks Again. Much obliged.
wow, awesome post.Thanks Again. Awesome.
Awesome blog.Thanks Again. Cool.
Thanks again for the article post.Much thanks again. Really Cool.
Thanks again for the article post. Want more.
Im obliged for the article.Much thanks again. Great.
I'm a husband who love culinary arts, and having fun together with my in laws.
It is actually very good whenever during autumn I devote a great deal of free timecooking with the help of my children, a little bit of entrees or a number of cake.
The best is plum pie, on the other hand love cookery meat loaf as well as other containers like that.
Also just like going on a vacation and then meetting innovative customers and new us.
Deliver me a PM if you appreciate my presentation !
Thanks!
<a h ref=”http://www.botoxinjections.net.” > Botox</a>
1 2 3 4 5 6 next »