您的位置:首页 > 编程语言 > PHP开发

PHP中的验证码类(验证码功能设计之一)

2016-04-21 20:54 453 查看
<!--vcode.class.php内容-->

<?php
class Vcode {
private $width; //宽
private $height; //高
private $num; //数量
private $code; //验证码

//构造方法, 三个参数
function __construct($width, $height, $num) {
$this->width = $width;
$this->height = $height;
$this->num = $num;
$this->code = $this->createcode(); //调用自己的方法
}

//获取字符的验证码, 用于保存在服务器中
function getcode() {
return $this->code;
}

//输出图像
function outimg() {
//创建背景 (颜色, 大小, 边框)
$this->createback();

//画字 (大小, 字体颜色)

//干扰元素(点, 线条)

//输出图像
}

//创建背景
private function createback() {

}

//画字
private function outstring() {

}

//设置干扰元素
private function setdisturbcolor() {

}

//输出图像
private function printimg() {

}

//生成验证码字符串
private function createcode() {
$codes = "3456789abcdefghijkmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY";

$code = "";

for($i=0; $i < $this->num; $i++) {
//返回随机字符
$code .=$codes{rand(0, strlen($codes)-1)};
}

return $code;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: