#native_company# #native_desc#

Number Verification, used to prevent form auto-completes

By Peter N
on July 18, 2007

Version: 2.0

Type: Full Script

Category: Graphics

License: WebSite Only

Description: This code contains two files, pic.php and numverif.php. numverify.php generates a random 10-character code using uppercase and lowercase letters, and numbers (A-Z,a-z,0-9). It send this information to pic.php, which takes the random code and inserts it into a .png image. The it prompts the user to enter the code. If correct, it says. If incorrect, it says. Very simple but may be modified. This is used to prevent forms from being auto-competed by some program. Have fun!

Two files.

To run, execute "numverify.php".

PHP4 with GD library is required.

===================== Save as numverify.php ====================================
define ('CHAR_COUNT', 8);
$num_ent=isset($_REQUEST['num_ent']) ? $_REQUEST['num_ent'] : 'none';
// The following omits characters that may be confused, like 0 O l 1 , etc.
if ($num_ent=='none') {
	$nums = array("5","6","7","8","d","e","1","2","3","4","f","g","h","j","k","9","a","b","c","m","n","p","q",

	// Create random array access keys to nums.
	$random_key = array_rand($nums, CHAR_COUNT);
	$random = "";

	for ($i=0;$i<CHAR_COUNT;$i++) {
		// Uses random access keys to access random elements in the array.
		$random = $random . $nums[$random_key[$i]];

	echo "<img src=pic.php?random=$random>";
	echo "<form action=" . $_SERVER['PHP_SELF'] . " method=post>
		Please type the code you see above. (CASE-SENSITIVE) <input type="text" name="num_ent"><br>
		<input type="hidden" name="random" value="$random">
		<p> </p><input type="submit" value="Submit">";
} else {
	if ($num_ent == $_REQUEST['random']) {
		// They got it right
		echo "Correct!";
	} else {   // They get it wrong.
			echo "Incorrect. Go back and refresh the page for a new code.";

===================== Save as pic.php ==========================================
$random=isset($_REQUEST['random']) ? $_REQUEST['random'] : 'ERROR';

header("Content-type: image/png");
$im = @imagecreate(100, 40) or die("Cannot Initialize new GD image stream");
// 100,40 is the size of the image to be created (height,width)

$background_color = imagecolorallocate($im, 225, 225, 225); // background color R,G,B

$text_color = imagecolorallocate($im, 0, 0, 0); // text color R,G,B

imagestring($im, 5, 10, 10, $random, $text_color); 
// "5" is the font size and can be 1 to 5. 
// "10,10" is the x,y location inside given image