Jump to content

Check to see if form contains web address


dachshund

Recommended Posts

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

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

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';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.