Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

A not to complicated captcha. - PHP Code Bank


A not to complicated captcha.
A not to complicated captcha.
                <?php

/* Made by TheMasterSinner */

// start session
session_start();

// make image
$image = imagecreate(65, 25);

// define some colors
$black  = imagecolorallocate($image, 0, 0, 0);
$white  = imagecolorallocate($image, 255, 255, 255);
$red    = imagecolorallocate($image, 255, 0, 0);
$green  = imagecolorallocate($image, 0, 255, 0);
$blue   = imagecolorallocate($image, 0, 0, 255);
$yellow = imagecolorallocate($image, 255, 255, 0);

// set the background colour
imagefill($image, 0, 0, $black);

// put some colored lines on the image
imageline($image, 0, rand(0, 25), 64, rand(0, 25), $red);
imageline($image, 0, rand(0, 25), 64, rand(0, 25), $blue);
imageline($image, 0, rand(0, 25), 64, rand(0, 25), $green);

// put a border on the image
imagerectangle($image, 0, 0, 64, 24, $yellow);

// make a 6 character string
$rndstr = md5(rand());
$rndstr = substr($rndstr, 0, 6);
$rndstr = strtoupper($rndstr);

// set the session to the random string
$_SESSION['captcha'] = $rndstr;

// write the string to the image
imagestring($image, 10, 6, 5, $rndstr, $white);

// change the content type to a png image
header('Content-type: image/png');

// echo  image
imagepng($image);

// finished, so destroy the image
imagedestroy($image);
?>
            
Comments
ghost's avatar
ghost 15 years ago

I could've sworn I already commented on this one… but, since I didn't, very nice job. Your code tends to be simple and clean… both of which I can appreciate. This does what it says on the title. Submit more! :)