Jump to content

Check to see if form contains web address


Go to solution Solved by 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

Edited by denno020

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';
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.