|
Posted by J.O. Aho on 11/10/06 15:04
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
Navigation:
[Reply to this message]
|