注册 登录
编程论坛 PHP技术论坛

求PHP验证码代码!!!

赤那 发布于 2011-03-18 17:46, 1157 次点击
要清晰漂亮的验证码!!!
2 回复
#2
gupiao1752011-03-24 14:18
百度GOOGLE上一大丢PHP验证码。为何不自己研究下呢?如果要现场的,我这里有一个,参考下!

程序代码:
<?php
session_start();
header("content-type:image/png");
$code = strtoupper(substr(md5(rand()),0,5));
$_SESSION['yzm']=$code;
$nimg=imagecreate(110,30);
imagecolorallocate($nimg,233,233,233);
for($i=0;$i<strlen($code);$i++){
    $font=mt_rand(6,9);
    $x=mt_rand(2,8)+200*$i/10;
    $y=mt_rand(2,4);
    $color=imagecolorallocate($nimg,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
    imagesetpixel($nimg, mt_rand()%70 , mt_rand()%30 , $color);
    imagestring($nimg,$font,$x,$y,$code[$i],$color);
    }
imagepng($nimg);
imagedestroy($nimg);
?>

#3
xeon8152012-08-01 18:57
这个是我自己写的。可以参考下。。
<?php
session_start();
$_SESSION['verify']=yzm();
function yzm($width=100,$height=50,$length=4,$type=3,$imageType='jpeg'){
    switch($type){
        case 1:
            $str=join('',array_rand(range(0,9),4));
            break;
        case 2:
            $str=implode('',array_rand(array_flip(range('a','z')),4));
            break;
        case 3:
            for($i=0;$i<$length;$i++){
                $string='abcdefghijkmnpqrstuvwxyABCDEFGHJKLMNPQRSTUVWXY23456789';
                $string=str_shuffle($string);
                $str.=substr($string,0,1);
            }
            break;
    }
    $img=imagecreate($width,$height);
    imagefilledrectangle($img,0,0,$width,$height,lightColor($img));
    for($i=0;$i<50;$i++){
        imagesetpixel($img,mt_rand(1,$width),mt_rand(1,$height),darkColor($img));
    }
    for($i=0;$i<5;$i++){
        imagearc($img,mt_rand(20,$width),mt_rand(20,$height),mt_rand(20,80),mt_rand(20,80),mt_rand(0,90),mt_rand(180,360),lightcolor($img));
    }
    for($i=0;$i<$length;$i++){
        $x=ceil($width/$length)*$i;
        $y=mt_rand(0,$height-20);
        imagechar($img,5,$x,$y,$str[$i],darkColor($img));
    }
    $headerStr='Content-type:image/'.$imageType;
    $func='image'.$imageType;
    if(function_exists($func)){
        header($headerStr);
        $func($img);
    }else{
        exit('当前服务器不支持该类型图片');
    }
    imagedestroy($img);
    return $str;
}
function lightColor($img){
    return imagecolorallocate($img,mt_rand(130,255),mt_rand(130,255),mt_rand(130,255));
}
function darkColor($img){
    return imagecolorallocate($img,mt_rand(0,125),mt_rand(0,125),mt_rand(0,125));
}
?>
1