Random Number Verification – Simple Form Authentication Using PHP

by Hiroshi on June 19, 2008

in Form Validation, Security, Spam Control

This is simple form authentication by a random number generated by PHP and authenticated by javascript. It can be used for spam control.

~~~ Head Section Code ~~~

PHP Code

$mynumber= rand(673,62389);
echo $mynumber;

Javascript Code

<script type="text/javascript">
//defining variable and storinging in script
var randomnumber= <?= $mynumber?>;
// Validating
function CheckData()
if(q.value != randomnumber)
alert("Please Enter Correct Number");
return false;
return true;

~~~ Body Section Code ~~~

Form Code

<form name="mail" action="go.php" method="post" onsubmit="return CheckData()">
<input type="text" name="q">
<input type="submit" name="Submit" value="Submit">

Random Number Verification PHP Script Download

Related Posts

Previous post:

Next post: