<?php
/**
*
*/
// $code = new VerifyCode(4,2,100,50);
$code = new VerifyCode();
// echo $code->code;
$code->outImage();
class VerifyCode
{
// 验证码个数
protected $number;
// 验证码类型
protected $codeType;
// 验证码宽度
protected $width;
// 验证码高度
protected $height;
// 图像资源
protected $image;
// 验证码字符串
protected $code;
// 构造函数,初始化对象需要传入个数,类型,宽度和高度,不传则默认值
function __construct($number=4, $codeType=2, $width=100, $height=50)
{
// 初始化成员属性
$this->number = $number;
$this->codeType = $codeType;
$this->width = $width;
$this->height = $height;
// 生成验证码,调用生成验证码函数creatCode()
$this->code = $this->creatCode();
// echo $this->code;
}
// 外部只允许读取code,不允许修改
public function __get($name){
if ($name = 'code') {
return $this->code;
}
return false;
}
protected function creatCode(){
// 通过验证码类型