Wednesday, 3 May 2017

php - How can i prevent sql injection but keep " and '?



How do prevent sql injection in php but still show " and '? A the moment I am using




$input = strip_tags($input);
$input = htmlentities($input);


However the output is \" and \'. Is there anyway I can show " and ' without the slashes but keep them there so I don't get injected?


Answer



First, that code is not stripping backslashes, of course they're still there. Use stripslashes() to take out backslashes, but DON'T DO IT.
If you see those slashes in the DB, and you HAVE USED mysql_real_escape_string, chances are you have magic_quotes_gpc on, and you're just adding another set of slahses. Remove those auto added first and then apply mysql_real_escape_string, they won't show this way but will still be there and make for a safe use in querying your DB.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...