View Full Version : Image verification

08-07-2007, 11:13 AM
I want to make an image verification for user registration verification code. I just can't find a way to make the code.. Can someone help me? Really need the help. Thank you

08-07-2007, 11:52 AM
There are plenty of posts here on forums, and even a good captcha snippet in snipets subforum. Use search little billy ;)

08-07-2007, 12:42 PM
first you need to make sure your hosting server has php compiled with the GD library and has it enabled.
then what you will want to do is make a random string, here is a quick example (Note: there are lots of ways to do this and this way may be considered unorthodox)

$string = md5(rand(1, 1000));
$split = str_split($string, 6);
echo $split[0];

this outputs something similar to:

and now you have a 6 digit verification code, next what you will want to do is create an image displaying this information.

$string = md5(rand(1, 1000));
$split = str_split($string, 6);

header("Content-type: image/png");
$image = imagecreate(200, 50)
or die("Error");
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 000, 000, 000);
imagestring($image, 5, 5, 5, "$split[0]", $text_color);

this makes a dynamic image that displays the random string

then you need to verify that they have entered the correct digits,
i suggest doing this by creating a session variable thats value is the correct digit combination and in the next script it checks the digits entered against the session variables value. Or you could do real time checking and code up a storm in javascript or ajax.
Hope this has helped