Forms Image Verification
Back to Example

 <!-- I am using a mysql database and also 16 or so images which display randomly. The images are a 6-digit code which is displayed to the user. You can use variations of course by making the digits longer or shorter, 25 digits, 3 digits, that is up to you. You can use Microsoft Access applying the same principal - however you will need to change your connection strings. Database specs: See the following line below: mysql_connect("server", "database","password") or die(mysql_error()); > You will be substituting "server" with the server you are using such as localhost - or whatever server you are using. > Substitute "database" with the name of your database and "password" with your database password For your database, you will need 3 fields: > id - int(11) primary autoincrement > url - varchar(255) - this field will be the complete url of your image for example: http://bdchlibrary.com/codes/13.jpg this is the url for just one of my code images > code - varchar(10) - I place the actual characters from the image in this field --> <html> <head> <meta http-equiv="Content-Language" content="en-us"> <title>Forms Image Verification</title> <?php // grab the security image and code from the database $randCode=rand(1,16); // see below: substitute server for your server such as localhost or whatever // substitute database with the name of your database // substitute password with your database password //mysql_connect("server", "database","password") or die(mysql_error()); mysql_connect("server", "database","password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $result = mysql_query("SELECT id,url,code FROM codes WHERE id=".$randCode) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $id=$row['id']; $url=$row['url']; $dbcode=$row['code']; } // end grab if ($_POST) { $code=strtolower($_POST['code']); $securityCode=strtolower($_POST['securityCode']); if ($code<>$securityCode) { $user_msg = "</b><br><font color=red>An error has occurred, please re-check and re-enter the security code</font>"; } else { $user_msg = "</b><br><font color=green>Congratulations, you have entered the correct code!</font>"; } } ?> </head> <body> <form method="post" action="FormsImageVerification.php"> <center><table border="1" id="table1"> <tr> <td colspan="2">Enter the code shown below</td> </tr> <tr> <td><img border="0" src="<?php echo $url; ?>"></td> <td><input maxlength="6" type="text" name="securityCode"></td> </tr> <tr> <td colspan="2"> <p align="center"> <input type="hidden" name="code" value="<?php echo $dbcode; ?>"> <input type="submit" value="Verify" name="verify"></td> </tr> </table> <?php echo $user_msg; ?> </center> </form> </body> </html>