Hi all.
Even though Im familiar with php & sql I would really like a second oppinion on my method for "securing" all user input from evil things..
This is how I does it atm:
On all inputs from all kinds of fields i use only mysqli_real_escape_string (in the db layer).
When db stuff goes out again I use htmlentities on single lines (username, email, etc), and removeHTMLtags+nl2br for larger texts (description, pagecontent, etc).
Also, in my init class I use this:
if (get_magic_quotes_gpc()) {
$_GET = array_map('stripslashes', $_GET);
$_POST = array_map('stripslashes', $_POST);
$_REQUEST = array_map('stripslashes', $_REQUEST);
}
And here's the removeHTMLtags:
static function removeHTMLTags($str)
{
//allowed = a b br blockquote center div hr i li ol u ul p pre
$html_tags = array("abbr","acronym","address","applet","area","base","basefont",
"bdo","big","body","button","caption","cite","code",
"col","colgroup","dd","del","dfn","dir","dl","dt","em","fieldset","font",
"form","frame","frameset","h1","h2","h3","h4","h5","h6","head","html",
"iframe","img","input","ins","isindex","kbd","label","legend","link","map",
"menu","meta","noframes","noscript","object","optgroup","option","param",
"q","s","samp","script","select","small","span","strike","strong","style",
"sub","sup","table","tbody","td","textarea","tfoot","th","thead","title","tr",
"tt","var");
foreach ($html_tags as $tag)
{
$str = preg_replace("/<\/?" . $tag . "(.|\s)*?>/","" , $str);
}
return $str;
}
Imho this should be enough, and the input and output will match.
But, is this enough, or am I short of something ?