<?php
/********************************************************************
 *                           DirCMS验证码文件
 *                            -------------------
 *   begin                : 2010/6/1
 *   copyright            : (C) 2009 DirCMS
 *   email                : uuturn@126.com
 *
 *   $Id: checkcode.php,v 1.0.0 2010/6/1 1:04:01 M Exp $
 ********************************************************************/
require dirname(__FILE__).'/include/common.inc.php';
@session_start();
$randcode = ""; 
header("Pragma:no-cache\r\n");
header("Cache-Control:no-cache, must-revalidate\r\n");
header("Expires:0\r\n");
Header("Content-type: image/png");

$border = 1; //是否要边框 1要:0不要
$how = 4; //验证码位数
$w = $how*15; //图片宽度
$h = 22; //图片高度
$fontsize = 5; //字体大小
$im = ImageCreate($w, $h);
$bgcolor = ImageColorAllocate($im, 255, 255, 255);
ImageFill($im, 0, 0, $bgcolor);
if($border)
{
	$black = ImageColorAllocate($im, 0, 0, 0); 
	ImageRectangle($im, 0, 0, $w-1, $h-1, $black);
}

for($i=0; $i<$how; $i++)
{   
	$alpha_or_number = mt_rand(0, 1);
	if(CHECKCODE==1) // 数字
	{
		$str="1234567890";
	}
	else if(CHECKCODE==2) // 字母
	{
		$str="abcdefghijkmnpqrstuvwyz";
	}
	else // 数字+字母
	{
		$str="abcdefghijkmnpqrstuvwyz23456789";
	}

	$which = mt_rand(0, strlen($str)-1); 
	$code = substr($str, $which, 1); 
	$j = !$i ? 4 : $j+15; 
	$color3 = ImageColorAllocate($im, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100)); 
	ImageChar($im, $fontsize, $j, 3, $code, $color3); 
	$randcode .= $code; 
}
for($i=0; $i<5; $i++)
{   
	$color1 = ImageColorAllocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
	ImageArc($im, mt_rand(-5,$w), mt_rand(-5,$h), mt_rand(20,300), mt_rand(20,200), 55, 44, $color1); 
}
$_SESSION['checkcode'] = $randcode;
Imagepng($im);
ImageDestroy($im);
?>