Spam Protection Function for the Guestbook!

  • admin
  • Topic Author
  • Visitor
  • Visitor
18 years 11 months ago #4 by admin
Hello all,

We have been getting a lot of emails, asking us how you can protect agains automated robots submitting junk to your guestbooks. Bellow is a simple solution for this problem:

Copy and past this function into the file "functions.php", just before the ending php close tag:
Code:
function check_referer($referers) { // If there are any referrers in the list ... if (count($referers)) { $found = false; // Use the browsers referrer header. $temp = explode("/",getenv("HTTP_REFERER")); $referer = $temp[2]; if ($referer=="") { $referer = $_SERVER['HTTP_REFERER']; list($remove,$stuff)=split('//',$referer,2); list($home,$stuff)=split('/',$stuff,2); $referer = $home; } // Check agains list. for ($x=0; $x < count($referers); $x++) { if (eregi ($referers[$x], $referer)) { $found = true; } } // Refererer is blank. if ($referer =="") $found = false; if (!$found) { // You might alter this to print some sort of error of your own. echo "<b>You are submitting entry from an <b>unauthorized domain.</b><br><br>"; } return $found; } else { return true; } } ?>

Also, open the file "add.php", and place the following code on line 28, right after the "include("header.inc");" line;
Code:
$referers = array ('domain.com','www.domain.com','111.111.111.111'); if (!check_referer($referers)) { // Form was not submitted from the site so exit echo "<center><br><a href=\"javascript:history.go(-1)\" class=\"text\"><font color=red>NICE TRY! NOW GET LOST!</font></center>"; include("footer.inc"); exit; }

Make sure to replace:

domain.com -> YOUR ACTUAL DOMAIN
www.domain.com -> YOUR ACTUAL DOMAIN WITH WWW
111.111.111.111 -> THE ACTUAL IP OF YOUR DOMAIN (SERVER)

Please Log in or Create an account to join the conversation.

  • Visitor
  • Visitor
18 years 9 months ago - 11 years 2 weeks ago #36 by
Hello! When you say to insert the additional code into functions.php....what do you mean by the 'ending php close tag'? The original file ends with the following:
Code:
} return $string; } ?>

Do you mean I should insert the new code right after the "return $string;" and before the "}" bracket? The new code ends with two brackets and then a question mark as follows:
Code:
return true } } ?>

I'm not supposed to end up with two question marks am I? What should the last few lines of the code look like (help!)

Also...in the new code to go into the "add.php" file, it says to add it on line 28 right after the "include ("header.inc");" line. Did you mean line 18 instead of 28? That line is very near the top of the file. I want to be sure I'm adding it into the correct place

(Sorry if these are stupid questions! I don't really know or understand php.... I'm scared to make any changes that might wipe out my existing guestbook comments too (this won't do that will it?)

Thank you in advance
I think your guestbook is awesome by the way

Karen
Last edit: 11 years 2 weeks ago by Pete.

Please Log in or Create an account to join the conversation.

  • Anonymous
  • Visitor
  • Visitor
18 years 9 months ago #37 by Anonymous
Replied by Anonymous on topic Spam Protection Function for the Guestbook!
Hi again. Instead of waiting for an answer, I went ahead and added the new code to both function.php and add.php (by copying and pasting in Notepad program...uploading the new files to my server as text files and changing their names once uploaded,...to functions.php and add.php)

I put the new functions.php code addition just before the ending question mark in the original script. There is only one question mark there.

I put the new add.php code in what I believe is line 18...directly after the "include ("header.inc");" line.

I then tried to test by adding one of my own comments to the guestbook (which it should allow...) It did not add a comment, instead it displayed all of the text as script on my screen. I double-checked and don't think I left out any characters....what am I doing wrong?

Thanks again.........

Karen

Please Log in or Create an account to join the conversation.

  • Anonymous
  • Visitor
  • Visitor
18 years 9 months ago #38 by Anonymous
Replied by Anonymous on topic Spam Protection Function for the Guestbook!
Karen,

Please check your email for the answer.

Please Log in or Create an account to join the conversation.

More
18 years 7 months ago #53 by Quest
Is it possible to include in your preferences for replies one that disallows a reply if it has a URL inside it, or if it has the word "http" in it. I know there are preferences to rewrite swear words, but I thought that this would be a very handy addition to the guestbook. I love it, but my spam code (copied from above) doesn't seem to keep them out completely. Also if it was possible to ban particular emails that would get rid of those who post nuts messages just for fun.

Anyhoo, it was just an idea.
Other than that, the guestbook is pretty fab.
Love Quest

Please Log in or Create an account to join the conversation.

More
18 years 7 months ago #59 by Pete
Quest,

If you want to keep the spammers out 100% of the time, the best way to do that is to use image verification. Email me if you are interested in this.

DigiOz Webmaster
www.digioz.com

Please Log in or Create an account to join the conversation.

Time to create page: 0.130 seconds
Powered by Kunena Forum