封装了一个加单的php验证码功能类,超级详细,麻雀虽小五脏俱全

<?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(){
		// 通过验证码类型
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值