473,513 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

In email form how do we say "must be equal to X"?

Hi, we are getting a lot of spam through our PHP Feedback form, and have set
up a new field 'prove you're human', asking them to do some simple maths.

What is the command for the PHP script itself, to say "this field must be
equal to 9 or return the error page"?

Thanks!

Matt
Nov 10 '06 #1
12 3005
Matthew Wilson wrote:
Hi, we are getting a lot of spam through our PHP Feedback form, and have set
up a new field 'prove you're human', asking them to do some simple maths.

What is the command for the PHP script itself, to say "this field must be
equal to 9 or return the error page"?
Look up "captcha".

/m
Nov 10 '06 #2
Matthew Wilson wrote:
Hi, we are getting a lot of spam through our PHP Feedback form, and have
set up a new field 'prove you're human', asking them to do some simple
maths.

What is the command for the PHP script itself, to say "this field must be
equal to 9 or return the error page"?

Thanks!

Matt
Hi Matt,

Go to Wikipedia or something like that and search for an approach named
captcha.
It boils down to the fact that a simple Turingtest (with distored images) is
used to make sure the user is human and not a (simple) bot.
Don't buy a solution, many free captcha alternatives are out there. :-)

Regards,
Erwin Moller
Nov 10 '06 #3
Matthew Wilson wrote:
Hi, we are getting a lot of spam through our PHP Feedback form, and have set
up a new field 'prove you're human', asking them to do some simple maths.

What is the command for the PHP script itself, to say "this field must be
equal to 9 or return the error page"?

Thanks!

Matt

Check out the header() function.

BTW - this is a simplified form of CAPTCHA. It might be good enough for
your purposes - but you might want to follow the other recommendations
here and look for a CAPTCHA solution.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 10 '06 #4
Matthew Wilson wrote:
Hi, we are getting a lot of spam through our PHP Feedback form, and have set
up a new field 'prove you're human', asking them to do some simple maths.

What is the command for the PHP script itself, to say "this field must be
equal to 9 or return the error page"?
Just add another input of text type (you can name it what ever you want, say
fun), you random two values and make another input of hidden type (you can
call it what ever you want, but not the same as the previous, say real), then
on the script where you receive the form you compare the two values

---form page, must pe in this case a php page---
<?PHP
$a=rand(5, 15);
$b=rand(8, 20);
echo "How much is $a+$b?";
?>
<input type="text" name="real" value="<?PHP echo ($a+$b); ?>">
<input type="text" name="fun">
---eof--

--- the receiving script ---
/* Set this in top of your script */
if($_REQUEST['fun']!=$_REQUEST['real']) {
header("Location: http://www.example.com/errorpage.php");
exit;
}
--- eof ---
//Aho
Nov 10 '06 #5
"J.O. Aho" <us**@example.netwrote in message
news:4r************@mid.individual.net...
Just add another input of text type (you can name it what ever you want,
say fun), you random two values and make another input of hidden type (you
can call it what ever you want, but not the same as the previous, say
real), then on the script where you receive the form you compare the two
values
That's great but a little complex for our needs. The actual capture form is
HTML, only the receive script is PHP. Can you offer a simpler version which
just expects the number "5" rather than random numbers?

Here is the format we follow, and the relevant field that expects a 5 is
"human":

<?
// ------------- CONFIGURABLE SECTION ------------------------

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto = "yo**************@example.com" ;

$mailto =

// $subject - set to the Subject line of the email, eg
//$subject = "Feedback Form" ;

$subject = "Feedback" ;

// the pages to be displayed, eg
//$formurl = "http://www.example.com/feedback.html" ;
//$errorurl = "http://www.example.com/error.html" ;
//$thankyouurl = "http://www.example.com/thankyou.html" ;

$formurl =
$errorurl =
$thankyouurl =

$uself = 0;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$referee = $_POST['referee'] ;
$human = $_POST['human'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($email) || empty($comments) || empty($human)) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}

$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"Referred by: $referee\n" .
"2+3=$human\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" .
$headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;

?>
Thanks so much!

Matt
Nov 10 '06 #6
Matthew Wilson wrote:
"J.O. Aho" <us**@example.netwrote in message
news:4r************@mid.individual.net...
>Just add another input of text type (you can name it what ever you want,
say fun), you random two values and make another input of hidden type (you
can call it what ever you want, but not the same as the previous, say
real), then on the script where you receive the form you compare the two
values

That's great but a little complex for our needs. The actual capture form is
HTML, only the receive script is PHP. Can you offer a simpler version which
just expects the number "5" rather than random numbers?

Here is the format we follow, and the relevant field that expects a 5 is
"human":
The drawback with using a fixed value is that the spammer can adjust his
script to enter the value 5, so they would have a bit more work if the value
is random the best is really to store things in a session, show a disorted
image and ask what it says on it and compare the values from the session and
from the form.

//Aho
Nov 10 '06 #7
["Followup-To:" header set to comp.lang.php.]
Matthew Wilson wrote:
Hi, we are getting a lot of spam through our PHP Feedback form, and have set
up a new field 'prove you're human', asking them to do some simple maths.

What is the command for the PHP script itself, to say "this field must be
equal to 9 or return the error page"?
if ($_POST['human_proof'] != 9) {
// spammer
} else {
// ok
}

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Nov 10 '06 #8
["Followup-To:" header set to comp.lang.php.]
Matthew Wilson wrote:
The actual capture form is
HTML, only the receive script is PHP. Can you offer a simpler version which
just expects the number "5" rather than random numbers?

Here is the format we follow, and the relevant field that expects a 5 is
"human":

<?
// ------------- CONFIGURABLE SECTION ------------------------
define ( 'SPAMMER_URL', 'http://www.example.com/spammer.html' );
define ( 'SPAMMER_CHECK', '5' );
// $mailto - set to the email address you want the form
// sent to, eg
//$mailto = "yo**************@example.com" ;

$mailto =
<snip>
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
### With apologies for using a different code structure
if ( $_POST['human'] != SPAMMER_CHECK ) {
header( "Location: " . SPAMMER_URL );
exit ;
}
$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
<snip>

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Nov 10 '06 #9
Matthew Wilson wrote:
"J.O. Aho" <us**@example.netwrote in message
news:4r************@mid.individual.net...

>>Just add another input of text type (you can name it what ever you want,
say fun), you random two values and make another input of hidden type (you
can call it what ever you want, but not the same as the previous, say
real), then on the script where you receive the form you compare the two
values


That's great but a little complex for our needs. The actual capture form is
HTML, only the receive script is PHP. Can you offer a simpler version which
just expects the number "5" rather than random numbers?

Here is the format we follow, and the relevant field that expects a 5 is
"human":

<?
// ------------- CONFIGURABLE SECTION ------------------------

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto = "yo**************@example.com" ;

$mailto =

// $subject - set to the Subject line of the email, eg
//$subject = "Feedback Form" ;

$subject = "Feedback" ;

// the pages to be displayed, eg
//$formurl = "http://www.example.com/feedback.html" ;
//$errorurl = "http://www.example.com/error.html" ;
//$thankyouurl = "http://www.example.com/thankyou.html" ;

$formurl =
$errorurl =
$thankyouurl =

$uself = 0;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$referee = $_POST['referee'] ;
$human = $_POST['human'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($email) || empty($comments) || empty($human)) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}

$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"Referred by: $referee\n" .
"2+3=$human\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" .
$headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;

?>
Thanks so much!

Matt

Matt,

If you're always expecting the same number, your spambots will quickly
pick up on that and you're no longer secure.

Aho's response is good, and very easy to implement. The one thing I
should add, though, is to encrypt the hidden value some way. A one-way
hash would work, for instance. Then when they enter the value on the
form, encrypt it the same way and compare the results with what's in the
hidden field.

For instance:

<input type="text" name="real" value="<?PHP echo crypt($a+$b,
'oUrSeCrEt'); ?>">

And on the other end:

if(crypt($_REQUEST['fun'], 'oUrSeCrEt')!=$_REQUEST['real'] ...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 10 '06 #10
"Pedro Graca" <he****@dodgeit.comwrote in message
news:sl*******************@ID-203069.user.individual.net...
["Followup-To:" header set to comp.lang.php.]
Matthew Wilson wrote:
>Hi, we are getting a lot of spam through our PHP Feedback form, and have
set
up a new field 'prove you're human', asking them to do some simple maths.

What is the command for the PHP script itself, to say "this field must be
equal to 9 or return the error page"?

if ($_POST['human_proof'] != 9) {
// spammer
} else {
// ok
}
Thanks, that seems to work, although we amended it to:

if ($_POST['human'] != 9) {
header( "Location: $errorurl" );
exit ;
}
....then the rest of our script

What should "// spammer" be in your script? Should we have left that in, in
order to prevent all attacks? :-S

Matt
Nov 10 '06 #11
Following on from J.O. Aho's message. . .
>Matthew Wilson wrote:
>"J.O. Aho" <us**@example.netwrote in message
news:4r************@mid.individual.net...
>>Just add another input of text type (you can name it what ever you want,
say fun), you random two values and make another input of hidden type (you
can call it what ever you want, but not the same as the previous, say
real), then on the script where you receive the form you compare the two
values

That's great but a little complex for our needs. The actual capture form is
HTML, only the receive script is PHP. Can you offer a simpler version which
just expects the number "5" rather than random numbers?

Here is the format we follow, and the relevant field that expects a 5 is
"human":

The drawback with using a fixed value is that the spammer can adjust his
script to enter the value 5, so they would have a bit more work if the value
is random the best is really to store things in a session, show a disorted
image and ask what it says on it and compare the values from the session and
from the form.

//Aho

There is another very good reason for generating forms in PHP:
Mr.Spammer's friend finds a suitable form, and passes /the form/ to Mr.
Spammer. Mr. Spammer doesn't sit at IE typing in spam does he? He
hacks the GET or POST request that a browser would send. This is
something that any script-kiddie could do.

So how do you conquer that? It's no good you having
<pseudo code>
// prepare form in PHP
R := Random number
S := SpecialFunction(R)
form.hidden.fieldR := R
form.instruction := Please type S to validate

// validate submitted form in PHP
R := POST[fieldR]
Sform := POST[fieldS]
Sneeded := SpecialFunction(R)
If(Sform <SNeeded){ // bad form ...
</pseudo code>

Why is this no good? Because the same form can be reused time and time
again where R and S never change from the first time they were served.

So you need to give your forms a 'unique' request number and store that
in the session ready to match with a submitted form. For example:
<pseudo code>
// prepare form in PHP
R := Random number
SESSION[R] := R
S := SpecialFunction(R)
form.hidden.fieldR := R // 'hidden' is cosmetic only
form.instruction := Please type S to validate

// validate submitted form in PHP
Rform := POST[fieldR]
Rneeded := SESSION[R] // fetch from session
ClearFromSessionArray(R) // this is single shot!
if(Rform<>Rneeded){ ... hacking or double submit ...->}
Sform := POST[fieldS]
Sneeded := SpecialFunction(Rneeded)
If(Sform <SNeeded){ // bad form ...
</pseudo code>

This doesn't deal with other problems especially those who GET the form
fresh each time but you have made a start in the right direction.

--
PETER FOX Not the same since the bridge building business collapsed
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Nov 11 '06 #12

My function tests your human-ness, and if youre human, thanks you for
taking the test and displays the email address. Also, if you have
proven your humanity, the next time you come to the contact page, you
will be recognized by a coookie, and given the address without the
test.

<?php
ob_start();
//required for cookies to work
// including file must start output buffer - ob_start();
function spamProofEmail(){

$explanation = "
<p>Email Address:</p>
<p>Sorry, We get too much spam. <br>
You'll have to pass a little test to make sure <br>
you're human, and not a spam-bot.<br></p>";

$emailaddress = 'D***@ExampleDomain.com';// use StudlyCaps,

$thehumanstring = 'surfsup';
$formtext = "Please type the word <strong>$thehumanstring</strongin
the box";
$thenclick = "Then click here to get our email address.";

$sorry = "Sorry, I guess you didnt pass the test, please try again.";
$thankyou = '<BR>Thank you.<BR>';

// +++++++++++++++++++++++++++++++++++++++++++++++++

$thehumanstring = strtolower($thehumanstring);
$postlower = strtolower($_POST['humanstring']);
$formaction = $_SERVER['REQUEST_URI'];
if ($postlower == $thehumanstring){
setcookie("spambotno", "spambotno", time()+60*60*24*100, "/");
$speHTML .= $thankyou;
}
if (($_COOKIE['spambotno'] == "spambotno") OR ($postlower ==
$thehumanstring)){
$emaillower = strtolower($emailaddress);
$speHTML .= '<BR><a
href="mailto:'.$emaillower.'">'.$emailaddress.'</a>';
return $speHTML;
}

if (($_COOKIE['spambotno'] != "spambotno") && ($postlower !=
$thehumanstring)){
$speHTML .= $explanation;}
if (isset($_POST['humanstring'])){
if ($postlower != $thehumanstring){
$speHTML .= $sorry;}}

if (($_COOKIE['spambotno'] != "spambotno") && ($postlower !=
$thehumanstring)){

$speHTML .='
<form name="the_form" action="'.$formaction.'" method="POST">
'.$formtext.' <br>
<input type="text" name="humanstring" size="30">
<br />
<input type="submit" value="'.$thenclick.'">
</form>

<script language="JavaScript"><!--
document.the_form.humanstring.focus();
//--></script>
';
}
return $speHTML;
}

?>
<html>
<head></head>
<body>
This is our contact page:
<?php echo spamProofEmail(); ?>
</body>

Nov 14 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
17731
by: John Davis | last post by:
I want to know what's the differences between Request.Form("Field Name") and Request.QueryString("Field Name") OR they function exactly the same, which is to return the value of the field?? ...
2
5190
by: Mindful_Spirit | last post by:
I'm trying to set up a basic email feed back form like this, and was wondering about some basic configuration settings. I have used code from this website. I have it working just fine. I'm...
3
2676
by: Pavils Jurjans | last post by:
Hello, I have bumped upon this problem: I do some client-side form processing with JavaScript, and for this I loop over all the forms in the document. In order to identify them, I read their...
11
4147
by: Pete Wilson | last post by:
Hi folks -- The page at http://www.pwilson.net/submit-demo.html will not validate. The validator at http://validator.w3.org tells me I can't have an input inside a form. Would some kind...
9
21471
by: Dan | last post by:
I am trying to use Request.Form("__EVENTTARGET") to get the name of the control that caused a post back. It keeps returning "". I am not really sure why, this happens for all of my controls...
47
46131
by: sudharsan | last post by:
Hi could you please explain wat atoi( ) function is for and an example how to use it?
6
2406
by: KiwiGenie | last post by:
Hi..I am trying to make a search form. I am fairly new to access and could well be looking at it completely wrong. I have an unbound form with textboxes in the header for entering different search...
3
1892
by: eBob.com | last post by:
How does a "sub-form", i.e. one invoked by another form, determine anything about the form which brought it into existence, i.e., I suppose, instantiated it? I wanted to so something like this ......
1
3114
by: sj7272 | last post by:
Hi, I am building email marketing framework, my email templates go out to clients and I wish to include a "send to a friend" or "forward to a friend" link in the outbound email. I want to track...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.