I have an html form that will take data from a user and insert into a database. I want to protect against common attacks. Right now I'm using this to take the user input from $_post and store it in a new array $cleanVars
The data is just standard text and numerical data plus an email, so no urls or html formatted input (html should be stripped out).
I can't find any consistent recommendations on what needs to be used. Any recommentations on how to improve this:
[code=php]
foreach($_POST as $varname => $value)
{
$clean = trim($value);
$clean = striptags($clean);
$clean = mysql_real_escape_string($clean); // use inplace of addslashes
$clean = htmlentities($clean, ENT_QUOTES, 'UTF-8');
//create sanitized array
$cleanVars[$varname] = $clean;
}
[/code]