dachshund Posted January 9, 2010 Share Posted January 9, 2010 hi, I just wanted to check if a comment a user posts contains HTML, and if it does, to not allow it to be posted. this is my current php, any help would be very much appreciated! thanks. <?php $comment=$_POST['comment']; $name=$_POST['name']; $email=$_POST['email']; $website=$_POST['website']; $date=date("y/m/d h:i:s"); if($name && $email && $comment){ $sql="INSERT INTO `comments` (`name`, `email`, `website`, `articleid`, `comment`, `datetime`) VALUES ('$name', '$email', '$website', '$id', '$comment', '$date')"; $result=mysql_query($sql) or die(mysql_error()); if($result){ echo "Your comment was posted succesfully on the article \n"; echo $rows['title']; echo '<p><a href="view_article.php?id='; echo $id; echo '">Click here to go back to the article.</a></p>'; }else { echo "Sorry, your comment could not be posted. Please make sure you fill in all the fields marked with *.\n"; } }else { echo "Sorry, your comment could not be posted. Please make sure you fill in all the fields marked with *.\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/187883-check-comment-for-html/ Share on other sites More sharing options...
crabfinger Posted January 9, 2010 Share Posted January 9, 2010 How about this? $comment = str_replace(array('&','<','>'),array('&','<','>'),$comment); Link to comment https://forums.phpfreaks.com/topic/187883-check-comment-for-html/#findComment-991977 Share on other sites More sharing options...
Tazerenix Posted January 9, 2010 Share Posted January 9, 2010 why bother. Just when the person submits the posts use htmlspecialchars() to convert all the html entities to < and > and stuff. That way they can still post but you won't have dodgy html on your webpage ps: dam u crab lol, stole meh answer) Link to comment https://forums.phpfreaks.com/topic/187883-check-comment-for-html/#findComment-991979 Share on other sites More sharing options...
dachshund Posted January 9, 2010 Author Share Posted January 9, 2010 oh yeah i'll do that as well. it was more to stop spam comments though. i guess i just just put a more effective spam filter than just not allowing html though? thanks for your help. Link to comment https://forums.phpfreaks.com/topic/187883-check-comment-for-html/#findComment-991981 Share on other sites More sharing options...
Tazerenix Posted January 9, 2010 Share Posted January 9, 2010 you could sign up to reCaptcha or something and implement a captcha code into your code Link to comment https://forums.phpfreaks.com/topic/187883-check-comment-for-html/#findComment-991983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.