Aquesta funció protegeix contra injeccions SQL, XSS, javascript. Tot en una.
function netejar($str) {
if(!get_magic_quotes_gpc()) {
$str = addslashes($str);
}
$str = strip_tags(htmlspecialchars($str));
return $str;
}
Actualització: (ANTI-XSS)
Una altra funció que fa el mateix pero d'una manera més precisa i avançada.
via:
http://snipplr.com/view.php?codeview&id=9596
function _Strip_Tag($Str_Input)
{
@settype($Str_Input, 'string');
$Str_Input= @strip_tags($Str_Input);
$_Ary_TagsList= array('jav
ascript:', 'jav
ascript:', 'jav	ascript:', '<!-', '<', '>', '%3C', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '<', '\x3c', '\x3C', '\u003c', '\u003C', chr(60), chr(62));
$Str_Input= @str_replace($_Ary_TagsList, '', $Str_Input);
$Str_Input= @str_replace('
', '', $Str_Input);
return((string)$Str_Input);
}