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 Quote 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 (edited) Maybe you can check with strpos strpos($comment, "http://") Or using captcha Edited July 9, 2013 by ayoksus Quote 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 (edited) 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 Edited July 9, 2013 by denno020 Quote 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'; } Quote 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? Quote 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'){ Quote 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...
Solution dachshund Posted July 9, 2013 Author Solution 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'){ Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.