Update: I can't bring myself to delete the spam comments on this post. It's just too funny.
I recently needed to get a quick captcha up on a PHP site. I used to use captchator but they started putting their url in the image, so I threw together my own:
<?php
# Create the captcha image and line/text color
$captcha = imagecreatetruecolor(100, 30);
$white = imagecolorallocate($captcha, 255, 255, 255);
# Create some random coordinates
# for lines that will hopefully
# make the captcha harder to crack.
$x1 = rand(0, 33);
$x2 = rand(34, 66);
$x3 = rand(67, 100);
$y1 = rand(0, 15);
$y2 = rand(16, 30);
$y3 = rand(0, 15);
# Draw the crackbuster lines
imageline($captcha, $x1, $y1, $x2, $y2, $white);
imageline($captcha, $x2, $y2, $x3, $y3, $white);
imageline($captcha, $x1, $y2, $x2, $y1, $white);
imageline($captcha, $x2, $y1, $x3, $y2, $white);
# Create a
# random key
$string = "";
$key = substr(md5(microtime() * mktime()), 0, 5);
for($i = 0; $i < strlen($key); $i++) {
$string .= $key[$i] . " "; # Pad with spaces
}
# Write the string
# to the captcha
$x = rand(1, 20);
$y = rand(1, 15);
imagestring($captcha, 5, $x, $y, $string, $white);
# Encrypt and store
# the string in a session.
session_start();
$_SESSION['captcha_key'] = md5($key);
# Output the image.
header("Content-type: image/png");
imagepng($captcha);
?>
I just put that in /images/captcha.php, render it with a normal image tag, then validate their entered text against $_SESSION['captcha_key']. I have no idea how effective it will be...