php代码验证注册_完整代码:PHP 登录验证码

这个是验证码制作经典类

*/

class Vcode{

private $width; //验证码宽度

private $height; //验证码高度

private $codeNum; //验证码字符个数

private $disturbColorNum; //干扰元素数量

private $checkCode; //验证码字符

private $image; //验证码资源

private $str; //生成的字符

function __construct($width=80,$height=20,$codeNum=5,$nan=1){

$this->width=$width;

$this->height=$height;

$this->codeNum=$codeNum;

//设置验证码干扰程度;

switch($nan){

case 1:$this->disturbColorNum=rand(2, 5); break;

case 2:$this->disturbColorNum=rand(5, 7); break;

case 3:$this->disturbColorNum=rand(7, 9); break;

case 4:$this->disturbColorNum=rand(11, 15); break;

case 5:$this->disturbColorNum=rand(15, 20); break;

default:$this->disturbColorNum=35;

}

$this->image=imagecreatetruecolor($this->width, $this->height);

}

/**

*/

function index(){

$size=rand(3, 5);

$bai=imagecolorallocate($this->image, 255, 255, 255);

imagefill($this->image, 0, 0, $bai);

$this->ganrao($this->disturbColorNum);

$this->str($this->codeNum);

for ($i=0;$istr);$i++){

$x=floor($this->width/$this->codeNum)*$i+3;

$y=rand(0, $this->height-imagefontheight($size));

imagechar($this->image, $size, $x, $y,$this->str[$i] , imagecolorallocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255)));

}

imagepng($this->image);

$this->jiancha();

}

/**

生成字符(大写字母 ,小写字母,数字)

@param int $num 生成字符的个数

*/

function str($num){

$str=array();

for ($i=0;$i

$arr=array(chr(rand(48, 57)),chr(rand(97,122)),chr(rand(65,90)));

$str[]=$arr[rand(0, 2)];

}

$this->str=$str;

}

/**

干扰点,线函数

*/

function ganrao($num){

//生成线

for($i=0;$i

imageline($this->image, rand(0,$this->width), rand(0, $this->height), rand(0,$this->width), rand(0, $this->height),imagecolorallocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255)));

}

//生成点

for($i=0;$i

imagesetpixel($this->image, rand(0,$this->width), rand(0,$this->height), imagecolorallocate($this->image, rand(0, 255), rand(0, 255), rand(0, 255)));

}

}

/**

检查 格式有更好的移植性

*/

function jiancha(){

if(function_exists("imagegif")){

header("content-type:image/gif");

}else if(function_exists("imageipeg")){

header("content-type:image/jpeg");

}else if(function_exists("imagepng")){

header("content-type:image/png");

}else if(function_exists("imagewbmp")){

header("content-type:image/vnd.wap.wbmp");

}else{

die("在PHP服务器中不支持图像!");

}

}

function session(){

return $this->str;

}

function __destruct(){

imagedestroy($this->image); //释放图像资源

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值