Visual Confirmation System

Submitted by GHS, Mar 2007.
This tutorial will explains how to put a visual confirmation in your register form.

In somewhere on page of form, add:
Code:
  1. <?php  
  2. /* generating the random number */  
  3. $rand = rand(11111,99999);  
  4.  
  5. /* generating the image */  
  6. if (isset($_GET['mode'] && $_GET['mode'] == 'image')  
  7. {  
  8.  session_start();  
  9.  $_SESSION['code'] = md5($rand);  
  10.  $img = imagecreate(50, 20);  
  11.  $bkg = imagecolorallocate($img, 0, 0, 0);  
  12.  $color = imagecolorallocate($img, 255, 255, 255);  
  13.  imagestring($img, 5, 2, 2, $rand, $color);  
  14.  header('Content-type:image/gif');  
  15.  imagegif($img);  
  16.  imagedestroy($img);  
  17.  exit;  
  18. }  
  19.  
  20. ?>  
  21. <fieldset>  
  22.  <legend>Visual Confirmation</legend>  
  23.  <div style="float:left"><input type="text" name="visualconfirm" value="" /></div>  
  24.  <div style="float:right"><img src="index.php?mode=image" alt="" /></div>  
  25.  <div style="clear:both"></div>  
  26. </fieldset> 
Now in other file (specified on <form action="HERE"...> before the fields of form) add:
Code:
  1. <?php  
  2. session_start();  
  3.  
  4. $field = isset($_POST['visualconfirm']) ? $_POST['visualconfirm'] : '';  
  5.  
  6. if (md5($field) == $_SESSION['code'])  
  7. {  
  8.  // action doed if confirmation code filled on field is correct  
  9. }  
  10. else  
  11. {  
  12.  // action doed if confirmation code filled on field is incorrect  
  13. }  
  14.  
  15. ?> 
P.S.: Don't forgot that you must put the submit button in your form.

Share this tutorial

If you want to show this tutorial to someone else please use following code to link to this tutorial:
HTML Link:
Forum BBCode:
Content of this tutorial may not be published anywhere else without author's permission. Please link to this page instead.