<?php
/*
October 2004
*** Random Image-Password Generator ***
This script generates a random string, displayed
on an image.
It can be very useful to prevent bots from automatic
logins or sign-ups.
Example:
You have a form and you want to be sure that no bots
automatically sign-up to gain e.g. extra credit.
To prevent this, let the user type the 'random' string,
that is displayed on the image, in a field. When this is
correct, you're sure that it's a human filling in :)
NOTE: You need to have GD library installed!!!
by Tri Pham
www.tripham.nl
tri[at]tripham.nl
*/
$width = 200; // width of image
$height = 80; // height of image
$len = 10; // length of string
$fontsize = 5; // fontsize
unset($random_text);
$lchar = 0;
$char = 0;
/**************************************************
$random_text will hold the secret and random text!
**************************************************/
// create 'random' text
for($i = 0; $i < $len; $i++) {
while($char == $lchar) {
$char = rand(48, 109);
if($char > 57) $char += 7;
if($char > 90) $char += 6;
}
$random_text .= chr($char);
$lchar = $char;
}
$fontwidth = ImageFontWidth($fontsize) * strlen($random_text);
$fontheight = ImageFontHeight($fontsize);
// create handle for image
$im = @imagecreate($width,$height);
// white background
$background_colour = imagecolorallocate($im, 255, 255, 255);
// give the 'random' text a nice colour
$text_colour = imagecolorallocate($im, rand(0,100), rand(0,100), rand(0,100));
// give the border a colour too ;)
imagerectangle($im, 0, 0, $width-1, $height-1, $text_colour);
// draw the string horizontally
imagestring($im, $fontsize, rand(3, $width-$fontwidth-3), rand(2, $height-$fontheight-3), $random_text, $text_colour);
// lets output!
header("Content-type: image/png");
imagepng($im,'',80);
imagedestroy($im);
?>
<?php
/*
October 2004
*** Random Image-Password Generator ***
This script generates a random string, displayed
on an image.
It can be very useful to prevent bots from automatic
logins or sign-ups.
Example:
You have a form and you want to be sure that no bots
automatically sign-up to gain e.g. extra credit.
To prevent this, let the user type the 'random' string,
that is displayed on the image, in a field. When this is
correct, you're sure that it's a human filling in :)