/    Sign up×
Community /Pin to ProfileBookmark

Spam protection

I’m trying to add a bit of home grown spam protection to an online form. I’m sure you all have seen and created similar solutions. Basically I’m just asking the user to add two numbers and input the answer, if answered correctly the form submits. However, I’m sure this will be beat in no time, so I was wondering if there was a built in function to convert a digit to a character:

9 + 1 =
to
nine plus one equals

Or do I need to hammer this out by hand?

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@TJ111Feb 20.2008 — Not that I know of. All you really need is an array that references the string to numbers though.
[code=php]
$conversion = array("nine"=>9, "eight"=>8); //etc
[/code]
Copy linkTweet thisAlerts:
@Doc_ThirstauthorFeb 21.2008 — Hey thanks, good suggestion. I'm ended up using something slightly more robust, but only marginal. Anyway, I'm still getting spam sent from my site. I'm starting to believe there must be a fundamental flaw in my code. Perhaps someone could help me out. This is referenced with a include ''; statement:

[CODE]<?php
echo "<br>";
$action = $_GET['action'];

if($action == "update")
{
$date = date("m/d/Y");
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$project = $_POST['project'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$rantest = $_POST['rantest'];
$answer = $_POST['answer'];

require ("ClassMathGuard.php");
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code']))
{
echo "<br><Br>";
echo "<table width=90% align=center border=0 class=body>";
echo "<tr>";
echo "<td align=center colspan=2>";
echo "<b>The following was sent to xxxxxxxxxxxxx:</b>";
echo "<br><br>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=30%>";
echo "Name: ";
echo "</td>";
echo "<td>";
echo "$name";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=30%>";
echo "Phone: ";
echo "</td>";
echo "<td>";
echo "$phone";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=30%>";
echo "E-mail: ";
echo "</td>";
echo "<td>";
echo "$email";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=30%>";
echo "Project: ";
echo "</td>";
echo "<td>";
echo "$project";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=30%>";
echo "Subject: ";
echo "</td>";
echo "<td>";
echo "$subject";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=30%>";
echo "Message: ";
echo "</td>";
echo "<td>";
echo "$message";
echo "</td>";
echo "</tr>";
echo "</table>";
$frommail = "From: $email";
$message = "Date: $date rnName: $name rnPhone: $phone rnE-mail: $email rnProject: $project rnSubject: $subject rnMessage: $message";
mail('xxxxxxxxxxxxxx', 'Service Request', $message, $frommail);
}
else
{
echo ("You math is either bad, or you are a bot. Please press back and resubmit.");
die();
}
}
else
{
echo "<table width=90% align=center border=0 class=body>";
echo "<tr>";
echo "<td colspan=2>";
echo "<b>Email</b>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2 align=center>";
echo "<a href=mailto:xxxxxxxx class=links>xxxxxxxxxx</a><br><br>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2>";
echo "<b>Phone</b>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2 align=center>";
echo "000-000-0000<br><br>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2>";
echo "<b>Submit Information Form</b><Br><Br>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2 align=center>";
echo "<form action=index.php?page=contact&action=update method=post>";
echo "<table cellpadding=0 cellspacing=0 border=0 width=100% class=body>";
echo "<tr>";
echo "<td align=right width=40%>";
echo "Name: ";
echo "</td>";
echo "<td>";
echo " &nbsp <input type=text name=name>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2>";
echo "<br>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=40%>";
echo "Phone: ";
echo "</td>";
echo "<td>";
echo " &nbsp <input type=text name=phone>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2>";
echo "<br>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=40%>";
echo "Email: ";
echo "</td>";
echo "<td>";
echo " &nbsp <input type=text name=email>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2>";
echo "<br>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=40%>";
echo "Project Type: ";
echo "</td>";
echo "<td>";
echo " &nbsp <select name=project>";
echo "<option>";
echo "<option>Painting";
echo "<option>Light Construction";
echo "<option>Other";
echo "</select>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2>";
echo "<br>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=40%>";
echo "Subject: ";
echo "</td>";
echo "<td>";
echo " &nbsp <input type=text name=subject size=50>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=2>";
echo "<br>";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=right width=40%>";
echo "Message: ";
echo "</td>";
echo "<td>";
echo " &nbsp <textarea name=message cols=40 rows=4></textarea>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan=2 align=center><br><br>";
require("ClassMathGuard.php"); MathGuard::insertQuestion();
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=center colspan=2>";
echo "<br><br><input type=submit value=Submit>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
echo "</td>";
echo "</tr>";
echo "</table>";

}
?>
[/CODE]
Copy linkTweet thisAlerts:
@Doc_ThirstauthorFeb 21.2008 — Ignore, my issue wasn't with this page of the site. It was how my include was referenced.
Copy linkTweet thisAlerts:
@diegomedeirosFeb 22.2008 — hey Doc Thirst,

add a hidden field to your form.You can validate this using:

[code=php]

<? if(empty($_POST['hidden'])){

//execute engine

}else{

die("SPAM!");

}

?>
[/code]


Only spammers can view the hidden field...?
Copy linkTweet thisAlerts:
@YelgnidrocFeb 22.2008 — Better still, hide the field using css, then spammers can't look for a hidden field
Copy linkTweet thisAlerts:
@iotaFeb 23.2008 — all I wish u to use - http://recaptcha.net
Copy linkTweet thisAlerts:
@diegomedeirosFeb 24.2008 — I don't use captcha. Captcha is very bad to accessibility...?
×

Success!

Help @Doc_Thirst spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...