经测试代码如下:
/**
* 建立英文数字验证码
*
* @param
* @author 编程之家 jb51.cc jb51.cc
**/
public function buildImageVerify(){
$image = imagecreate($width,$height);
$r = Array(225,255,223);
$g = Array(225,236,237,255);
$b = Array(225,166,125);
$keys = mt_rand(0,3);
$bg = imagecolorallocate($image,$r[$keys],$g[$keys],$b[$keys]);//背景色
$border = imagecolorallocate($image,100,100);
$stringColor = imagecolorallocate($image,mt_rand(0,200),120),120));
for ($i = 0; $i < 25; $i++) {
imagesetpixel($image,$width),$height),$stringColor);
}
for($i=0;$i<4;$i++){
$rand = dechex(mt_rand(0,15));
$num.=$rand;
imagestring($image,5,$i*10+5,mt_rand(1,8),$rand,$stringColor);
}
$_SESSION['verify'] = md5($num);
$this->out($image,$type);
}
原文链接:https://www.f2er.com/php/529037.html