用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3752|回复: 1
收起左侧

[其它 Other] 验证码?

[复制链接]
发表于 2009-5-20 04:45:31 | 显示全部楼层 |阅读模式
囧一个先。。应该足够用了吧
PHP复制代码
 
$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);
 
复制代码
发表于 2009-5-20 14:05:58 | 显示全部楼层
够短,偶稀饭~

本版积分规则