caincheung 发表于 2009-5-20 04:45:31

验证码?

囧一个先。。应该足够用了吧

$type='png';
$width=54;
$height=22;
Header("Content-type: image/".$type);
srand((double)microtime()*1000000);
$randval = sprintf("%04d", rand(0,9999));// verify_code

if ( $type!='gif' && function_exists('imagecreatetruecolor')) {
    $im = @imagecreatetruecolor($width,$height);
}else {
    $im = @imagecreate($width,$height);
}
$r = Array(225,255,255,223);
$g = Array(225,236,237,255);
$b = Array(225,236,166,125);
$key = rand(0,3);
$backColor = ImageColorAllocate($im, $r[$key],$g[$key],$b[$key]);//背景色(随机)
$borderColor = ImageColorAllocate($im, 0, 0, 0);//边框色
$pointColor = ImageColorAllocate($im, 0, 255, 255);//点颜色
@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor);
$stringColor = ImageColorAllocate($im, 255,51,153);
for($i=0;$i<=50;$i++){
    $pointX = rand(2,$width-2);
    $pointY = rand(2,$height-2);
    @imagesetpixel($im, $pointX, $pointY, $pointColor);
}
@imagestring($im, 5, 8, 3, $randval, $stringColor);
$ImageFun='Image'.$type;
$ImageFun($im);
@ImageDestroy($im);

visvoy 发表于 2009-5-20 14:05:58

够短,偶稀饭~
页: [1]
查看完整版本: 验证码?