View Single Post
  #3   Spotlight this post!  
Unread 14-04-2007, 03:22
ThomasP's Avatar
ThomasP ThomasP is offline
Registered User
FRC #1255 (Blarglefish)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Baytown, Texas
Posts: 100
ThomasP is just really niceThomasP is just really niceThomasP is just really niceThomasP is just really nice
Send a message via AIM to ThomasP
Re: Easiest way to block spam

Quote:
Originally Posted by artdutra04 View Post
The code looks good so far, but I found an error in the second block of code. The changes I made are added in red:
Code:
...
<input type="submit">
<?
    } else if($_POST['Bot'] == "No" || $_POST['HumanTest'] == "13" || strtolower($_POST['HumanTest'] == "thirteen")) {
        echo 'Hi ' . $_POST['name'] . '!'
    } else {
?>
Name: <input type="text" name="name">
...
This change fixes the single equals sign operator error, as well as added in a strtolower() command, so that if the user inputs Thirteen or tHirTeeN you know they still had the right answer.
Thanks artdutra, I've been doing too much with VB.NET and SQL at work lately, I kept starting to type "OR" instead of "||" also but managed to catch all of those mistakes.

I was thinking about the spam blocking code a minute ago and think there may actually be a better way to do the thing...

PHP Code:
<html>
<body>
<?PHP
    
if((strtolower($_POST['Bot']) != "thirteen" && $_POST['Bot'] != "13"))
        echo 
"You're a bot! Stop messing with my form!";
    else
        echo 
'Hi ' $_POST['name'] . '!';
?>
<form action="test.php" method="POST">
Name: <input type="text" name="name">
<script type="text/javascript" language="javascript">
document.write('<input type="hidden" id="Bot" name="Bot" value="Yes">');
document.getElementById('Bot').value = "13";
</script>
<noscript>
  What is eight plus five? <input type="text" id="Bot" name="Bot" />
</noscript>
<input type="submit">
</form>
</body>
</html>
I also caught another error when I actually tested that before posting... I had used apostrophes in my PHP strings and had one in "You're", switched that string to quotation marks.