<?php
    /**
     * script captcha.php
     * Dibuja un codigo de verificacion anti robot
     * @yield string $_SESSION captcha 
     */
	session_start();

	$charset = 'ACDEFGHKMNPQRTVWXY4579';
	$maxpos = strlen($charset) - 1;
	$captcha = '';
	$im = imagecreate(60, 24);
	$white = imagecolorallocate($im, 0xff, 0xff, 0xff);
	for ($i = 0; $i < 4; $i++) {
		$imchar = imagecreate(15, 24);
		$white = imagecolorallocate($imchar, mt_rand(0xe0, 0xff), mt_rand(0xe0, 0xff), mt_rand(0xe0, 0xff));
		$color = imagecolorallocate($imchar, mt_rand(0x00, 0x70), mt_rand(0x00, 0x70), mt_rand(0x00, 0x70));
		$captcha .= substr($charset, mt_rand(0, $maxpos), 1);
		imagestring($imchar, 5, 0, 0, $captcha[$i], $color);
		$imchar = imagerotate($imchar, mt_rand(-10, 10), $white);
		imagecopymerge($im, $imchar, mt_rand(2, 4) + $i * 15 , mt_rand(2, 6) , 0, 0, 15, 24, 100);
	}
	$_SESSION['captcha'] = $captcha;
	header('Content-type: image/gif');
	imagegif($im);
?>