Go to Post And the only thing that can really measure that is when you look a kid in the eye, say "We've got a problem..." and you see them smiling, "Bring it on." - dtengineering [more]
Home
Go Back   Chief Delphi > Technical > IT / Communications > Website Design/Showcase
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-04-2007, 19:30
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
Easiest way to block spam

Our guestbook has been attacked by spam bots quite a bit recently and I finally got around to stopping the spam with a neat little trick from the ASP.NET AJAX Control Toolkit that real users won't even notice (as long as they have Javascript enabled...)

PHP Code:
<?PHP
    
if($_POST['Bot'] == "Yes")
        echo 
'You're a botStop messing with my form!'
    else if($_POST['
Bot'] == "No")
        echo '
Hi ' . $_POST['name'] . '!'
?>
<form action="test.php" method="POST">
Name: <input type="text" name="name">
<input type="hidden" id="Bot" name="Bot" value="Yes">
<script type="text/javascript" language="javascript">
document.getElementById('
Bot').value = "No"
</script>
<input type="submit">
</form>
A lot of spam bots don't execute javascript so you are safe from them. For people that disable javascript, you can modify the above code to do something like...

PHP Code:
<form action="test.php" method="POST">
<?PHP
    
if($_POST['Bot'] == "Yes") {
?>
I'm not sure if you're a bot or not... what is five plus eight?<br />
<input type="text" name="HumanTest">
<input type="hidden" name="name" value="<? echo $_POST['name'?>">
<input type="submit">
<?
    
} else if($_POST['Bot'] == "No" || $_POST['HumanTest'] == "13" || $_POST['HumanTest'] = "thirteen") {
        echo 
'Hi ' $_POST['name'] . '!'
    
} else {
?>
Name: <input type="text" name="name">
<input type="hidden" id="Bot" name="Bot" value="Yes">
<script type="text/javascript" language="javascript">
document.getElementById('Bot').value = "No"
</script>
<input type="submit">
<? ?>
</form>
And that will allow regular people that have javascript enabled to not be bothered by proving they're human while also allowing for the occasional user that disables it.


Disclaimer: It has been a while since I've wrote any PHP so I can't guarantee any of that PHP code will work.
  #2   Spotlight this post!  
Unread 13-04-2007, 22:31
artdutra04's Avatar
artdutra04 artdutra04 is offline
VEX Robotics Engineer
AKA: Arthur Dutra IV; NERD #18
FRC #0148 (Robowranglers)
Team Role: Engineer
 
Join Date: Mar 2005
Rookie Year: 2002
Location: Greenville, TX
Posts: 3,078
artdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond reputeartdutra04 has a reputation beyond repute
Re: Easiest way to block spam

Quote:
Originally Posted by ThomasP View Post
Disclaimer: It has been a while since I've wrote any PHP so I can't guarantee any of that PHP code will work.
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.
__________________
Art Dutra IV
Robotics Engineer, VEX Robotics, Inc., a subsidiary of Innovation First International (IFI)
Robowranglers Team 148 | GUS Robotics Team 228 (Alumni) | Rho Beta Epsilon (Alumni) | @arthurdutra

世上无难事,只怕有心人.
  #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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cheapest and easiest way to slow down a motor sanddrag Technical Discussion 41 21-12-2005 07:26
Stinger Fuse Block and Power Distribution Block Don Wright Electrical 2 30-03-2004 10:45
Wicked Easy Way To Block Pop-up Adds! MattK Website Design/Showcase 18 17-02-2003 20:33
Anyone knowwhere to buy maxi block distribution block? BrianB Kit & Additional Hardware 0 23-01-2003 12:46
Any way to block out certain forums? Ken Leung CD Forum Support 5 02-09-2002 22:07


All times are GMT -5. The time now is 01:22.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi