I am currently using this process to Sanitize/Filter comment entered by users ->
This one is used to strip slashes... and
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
Then the comment goes through this function to sanitize the data...
function my_strip_tags($str) {
$strs=explode('<',$str);
$res=$strs[0];
for($i=1;$i<count($strs);$i++)
{
if(!strpos($strs[$i],'>'))
$res = $res.'<'.$strs[$i];
else
$res = $res.'<'.$strs[$i];
}
return strip_tags($res);
}
After this it goes straight into the database using prepared statement..
function add_comment($comment,$type,$update_id,$user_id){
$query="INSERT INTO comment_updates (updateid,userid,comment) VALUES(?,?,?)";
if($stmt=$this->conn->prepare($query)) {
$stmt->bind_param('sss',$update_id,$user_id,$comment);
$stmt->execute();
if($this->conn->affected_rows==1){
$stmt->close();
return true;
}
}
}
I just wanted to know if this is secure enough or if their are any other better alternatives...Thanks