Full source:
PHP Code:
<html>
<head>
<title>CAPTCHA</title>
</head>
<body>
<?php
session_start();
if (isset($_POST['submit']) &&
md5($_POST['textcode']) == $_SESSION['vcode']) {
die ('Correct');
} else {
echo ('Incorrect');
}
$string = md5(microtime() * mktime());
$string = substr($string, 0, 5);
$im = imagecreatefromjpeg('back.jpg');
$white_color = imagecolorallocate($im, 255, 255, 255);
imagestring($im, 5, 25, 7, $string, $white_color);
for($i = 0; $i < 5; $i++) {
imageline($im, rand(0, 100),rand(0, 20), rand(50, 100), rand(50, 100), $white_color);
}
imagejpeg($im, 'verify.jpg');
imagedestroy($im);
$_SESSION['vcode'] = md5($string);
?>
<form method="POST" action="">
<img src="verify.jpg"><br>
<input type="text" name="textcode">
<input type="submit" value="Verify" name="submit">
</form>
</body>
</html>