At the moment, I apply a ‘throw everything at the wall and see what sticks’ method of stopping the aforementioned issues. Below is the function I have cobbled together:
function madSafety($string) { $string = mysql_real_escape_string($string); $string = stripslashes($string); $string = strip_tags($string); return $string; }
However, I am convinced that there is a better way to do this. I am using FILTER_ SANITIZE_STRING and this doesn’t appear to to totally secure.
I guess I am asking, which methods do you guys employ and how successful are they? Thanks
Just doing a lot of stuff that you don’t really understand, is not going to help you. You need to understand what injection attacks are and exactly how and where you should do what.
In bullet points:
mysql_real_escape_string).stripslashes) when you retrieve data from the database.echo), you should default to escape the string (UsinghtmlentitieswithENT_QUOTES).strip_tagsis in theory what you should use, but it’s flawed; Use HtmlPurifier instead.See also: What's the best method for sanitizing user input with PHP?