Sunday 5 May 2019

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...