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;
}
}
<?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;
}
}
相关文章推荐
- PHPExcel读取excel文件示例
- getAttribute()与getParameter的区别
- PHP中的验证码类(准备篇)
- php干不了的活
- PHP中使用GD库方式画时钟
- PHP封装的图片大小调整类
- PHP等比例缩放图片
- OutputFormats
- fck配置图片上传(php版)
- PhpStorm 10.0注册
- PHP两个日期之间的所有日期
- PhpStorm11.0 配置在浏览器中打开文件
- PHP CI分页类带多个参数
- php获取内容中第一张图片地址
- [PDO绑定参数]使用PHP的PDO扩展进行批量更新操作
- php如何使用 phpqrcode 生成二维码
- phpstorm9如何配置interpreter
- PagerAdapter、FragmentPagerAdapter的使用
- PHP的错误机制总结
- PhP 常见安装错误configure error xml2-config not found. please check your libxml2 installation