dachshund Posted July 9, 2013 Share Posted July 9, 2013 Hi, I have a comment form which currently makes sure people do not post any html with the below code: <?php if(strlen($comment) != strlen(strip_tags($comment)) OR $name == '1' OR $comment == '1'){ ?> I am still getting a lot of spam that contains a web address such as http://www.viagra.com. To stop these comments going through, I want to check to see if a web address has been included in the $comment, and if so, not allow it. Can anyone help? Thanks Link to comment https://forums.phpfreaks.com/topic/279991-check-to-see-if-form-contains-web-address/ Share on other sites More sharing options...
ayoksus Posted July 9, 2013 Share Posted July 9, 2013 Maybe you can check with strpos strpos($comment, "http://") Or using captcha Link to comment https://forums.phpfreaks.com/topic/279991-check-to-see-if-form-contains-web-address/#findComment-1440031 Share on other sites More sharing options...
denno020 Posted July 9, 2013 Share Posted July 9, 2013 You could also use preg_match: if(preg_match("~(.*http://.*)|(.*www\.).*~", $comment)){ //there is some sort of a link in there } But as ayoksus said at the end of their comment, implement a basic captcha. I've done this on my site, I simply ask a math question, to add two numbers that are randomly selected from 0 to 10. Has completely cut off all spam. I made mine update via ajax when an incorrect guess is made, so that someone can't keep guessing on the same math problem, they get one shot at getting each right.. Hope that helps Denno Link to comment https://forums.phpfreaks.com/topic/279991-check-to-see-if-form-contains-web-address/#findComment-1440032 Share on other sites More sharing options...
dachshund Posted July 9, 2013 Author Share Posted July 9, 2013 Ok, so I tried this, but it doesn't seem to be working. Can anyone see where I've gone wrong. Thanks for your help. if ($pos === true) { $pos = '1'; } if (strlen($comment) != strlen(strip_tags($comment)) OR $name == '1' OR $comment == '1' OR $pos == '1'){ echo 'comment failed'; } Link to comment https://forums.phpfreaks.com/topic/279991-check-to-see-if-form-contains-web-address/#findComment-1440039 Share on other sites More sharing options...
denno020 Posted July 9, 2013 Share Posted July 9, 2013 Where would $pos get set to true? Link to comment https://forums.phpfreaks.com/topic/279991-check-to-see-if-form-contains-web-address/#findComment-1440042 Share on other sites More sharing options...
dachshund Posted July 9, 2013 Author Share Posted July 9, 2013 Sorry, here: $pos = strpos($comment, 'http://'); if ($pos === true) { $pos = '1'; } if (strlen($comment) != strlen(strip_tags($comment)) OR $name == '1' OR $comment == '1' OR $pos == '1'){ Link to comment https://forums.phpfreaks.com/topic/279991-check-to-see-if-form-contains-web-address/#findComment-1440045 Share on other sites More sharing options...
dachshund Posted July 9, 2013 Author Share Posted July 9, 2013 worked it out, it's $pos = strpos($comment, 'http://'); if ($pos !== false) { $pos = '1'; } if (strlen($comment) != strlen(strip_tags($comment)) OR $name == '1' OR $comment == '1' OR $pos == '1'){ Link to comment https://forums.phpfreaks.com/topic/279991-check-to-see-if-form-contains-web-address/#findComment-1440079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.