Visual Confirmation System
This tutorial will explains how to put a visual confirmation in your register form.
In somewhere on page of form, add:
In somewhere on page of form, add:
Code:
- <?php
- /* generating the random number */
- $rand = rand(11111,99999);
- /* generating the image */
- if (isset($_GET['mode'] && $_GET['mode'] == 'image')
- {
- session_start();
- $_SESSION['code'] = md5($rand);
- $img = imagecreate(50, 20);
- $bkg = imagecolorallocate($img, 0, 0, 0);
- $color = imagecolorallocate($img, 255, 255, 255);
- imagestring($img, 5, 2, 2, $rand, $color);
- header('Content-type:image/gif');
- imagegif($img);
- imagedestroy($img);
- exit;
- }
- ?>
- <fieldset>
- <legend>Visual Confirmation</legend>
- <div style="float:left"><input type="text" name="visualconfirm" value="" /></div>
- <div style="float:right"><img src="index.php?mode=image" alt="" /></div>
- <div style="clear:both"></div>
- </fieldset>
Now in other file (specified on <form action="HERE"...> before the fields of form) add:
Code:
- <?php
- session_start();
- $field = isset($_POST['visualconfirm']) ? $_POST['visualconfirm'] : '';
- if (md5($field) == $_SESSION['code'])
- {
- // action doed if confirmation code filled on field is correct
- }
- else
- {
- // action doed if confirmation code filled on field is incorrect
- }
- ?>
P.S.: Don't forgot that you must put the submit button in your form.