生成验证码代码如下(index.php):
public function captcha()
{
//初始化
$border = 1;
$how = 4;
$w = 117;
$h = 42;
$y = 29;
$fontsize = 18;
$alpha = "abcdefghjkmnpqrstuvwxyz";
$number = "23456789";
$captchacode = "";
srand((double)microtime()*1000000);
$font = __DIR__ . "font/arialbd.ttf";
$img = imagecreate($w, $h);
//绘制基本框架
$bgcolor = imagecolorallocate($img, 247, 255, 236);
imagefill($img, 0, 0, $bgcolor);
if ($border) {
$black = imagecolorallocate($img, 204, 204, 204);
imagerectangle($img, 0, 0, $w-1, $h-1, $black);
}
//逐位产生随机字符
$j = 0;
for ($i = 0; $i < $how; $i++) {
$alpha_or_number = mt_rand(0, 1);
$str = $alpha_or_number ? $alpha : $number;
$which = mt_rand(