php 输出session 验证码与图片不同步,图片总是快一步,求解!
本帖最后由 xdawei 于 2012-04-18 20:07:42 编辑 php 输出session 验证码与图片不同步,图片总是快一步,求解!
doimage();
$_session['code']=$checkcode->get_code();
*/
class checkcode {
//验证码的宽度
public $width=130;
//验证码的高
public $height=50;
//设置字体的地址
private $font;
//设置字体色
public $font_color;
//设置随机生成因子
public $charset = 'abcdefghkmnprstuvwyzabcdefghklmnprstuvwyz23456789';
//设置背景色
public $background = '#edf7ff';
//生成验证码字符数
public $code_len = 4;
//字体大小
public $font_size = 20;
//验证码
private $code;
//图片内存
private $img;
//文字x轴开始的地方
private $x_start;
function __construct($fontpath) {
$this->font =$fontpath;
}
/**
* 生成随机验证码。
*/
protected function creat_code() {
$code = '';
$charset_len = strlen($this->charset)-1;
for ($i=0; $icode_len; $i++) {
$code .= $this->charset[rand(1, $charset_len)];
}
$this->code = $code;
}
/**
* 获取验证码
*/
public function get_code() {
return strtolower($this->code);
}
/**
* 生成图片
*/
public function doimage() {
$code = $this->creat_code();
$this->img = imagecreatetruecolor($this->width, $this->height);
if (!$this->font_color) {