<?php
//当前由PHP生成图片文件
header("Content-type:image/png");

$im 				=@imagecreate(60, 23) or die("Cannot Initialize new GD image stream");
$background_color	=imagecolorallocate($im,255,255,255);
$text_color			=imagecolorallocate($im,0,0,0);

$code=rand(1000,9999);

$domain=$_SERVER['HTTP_HOST']=='localhost' ? false : $_SERVER['HTTP_HOST'];
//设置供验证码用的cookie
setcookie("captcha",$code,time()+3600,'/',$domain,false,true);  

imagestring($im, 5, 3, 3, $code, $text_color);
imagepng($im);
imagedestroy($im);

?>