...

View Full Version : Guestbook Anti-Spam Help



CosmicGraffiti
06-25-2005, 10:05 AM
My guestbook gets spammed around 2 or more times a dayw with gamling and poker ads. Could someone help how to make an anti-spam for my guestbook.
I don't want to use IP banning, coz the spammer uses a lot of different IPs on evry posts.
I want it whenever a guest submits a post and the words "poker, gamling, casino etc." is on the message, an error message would display and it won't be added on the guestbook.
Does someone know how could I do that? I posted my PHP file that adds the entry to the guestbook:



<?php include("navigation.txt");

include("mydb.php");

$name = $_POST['gbname'];
$email = $_POST['gbemail'];
$website = $_POST['gbwebsite'];
$message = $_POST['gbmessage'];
$ip = $_POST['ip'];
$date = $_POST['date'];

// check if there are any blank entry
if ($name == '' || $email == '' || $message == '' || $date == '' || $ip == '')
{
echo "<p class=\"head\">Error!</p>Please go back and fill in all the required fields!<br>";
include("tagboard.txt");
die("&nbsp;");

}

else {


$message = str_replace("<","&lt;",$message);
$message = str_replace(">","&gt;",$message);
$message = str_replace("\n","<br>",$message);

$message = str_replace(":)","<img src=smiley/yellow_smilies/smile.gif border=0>",$message);
$message = str_replace(":(","<img src=smiley/yellow_smilies/sad.gif border=0>",$message);
$message = str_replace(":P","<img src=smiley/yellow_smilies/tongue.gif border=0>",$message);
$message = str_replace(":D","<img src=smiley/yellow_smilies/teeth.gif border=0>",$message);
$message = str_replace("8)","<img src=smiley/yellow_smilies/sunglass.gif border=0>",$message);
$message = str_replace(":[","<img src=smiley/yellow_smilies/mad.gif border=0>",$message);
$message = str_replace("%)","<img src=smiley/yellow_smilies/confused.gif border=0>",$message);
$message = str_replace("*)","<img src=smiley/yellow_smilies/rosycheek.gif border=0>",$message);


$q = "INSERT into guestbook (id,name,email,website,date,ip,message) VALUES ('$id','$name','$email','$website','$date','$ip','$message')";
$result = mysql_query($q,$connection);

if ($result)
{
echo "<p class=\"head\">Guestbook Entry</p>Thank you, <b>$name</b>! Your entry has been added to the guestbook! Click <a href=\"guestbook.php\">here</a> to return to the guestbook.";
}
else { echo "Can't connebt to MySQL! Please report this to the webmaster."; include("tagboard.txt");
die ("&nbsp;");
}
}
include("tagboard.txt"); ?>

chump2877
06-25-2005, 10:13 AM
Just use one of the string functions (http://us3.php.net/strings) with $message to locate all occurrences of a certain substring within the larger string....if the function finds one of the offending substrings (i.e., "poker"), then display your error message and keep the form from being submitted.....

Sounds like you kind of already know what you need to do.... ;)

CosmicGraffiti
06-25-2005, 10:18 AM
Just use one of the string functions (http://us3.php.net/strings) with $message to locate all occurrences of a certain substring within the larger string....if the function finds one of the offending substrings (i.e., "poker"), then display your error message and keep the form from being submitted.....

Sounds like you kind of already know what you need to do.... ;)

*gulp* I actually dunno how to code it...

EDIT: I found this http://us3.php.net/manual/en/function.strpbrk.php
Is this what I should use?

chump2877
06-25-2005, 11:03 AM
Try this one instead: http://us3.php.net/manual/en/function.stripos.php

An example of how strpos() is used (also at this URL):


<?php
$findme = 'a';
$mystring1 = 'xyz';
$mystring2 = 'ABC';

$pos1 = stripos($mystring1, $findme);
$pos2 = stripos($mystring2, $findme);

// Nope, 'a' is certainly not in 'xyz'
if ($pos1 === false) {
echo "The string '$findme' was not found in the string '$mystring1'";
}


Edit: So, in your case, you would say something like:


if ($pos1 === true) {
die("Unable to add guest book entry");
}

to kill the script or whatever you want to do when you find one of these words.....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum