您正在使用 IPV4 [52.54.103.76] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
悟空收录网       [公益]保护绿色环境,构建和谐社会      

【腾讯云】 爆款2核2G3M云服务器首年 61元,叠加红包再享折上折      
[公益] 地球是我家,绿化靠大家      
2024年 清明节 006
2024年 劳动节 033
2025年 元 旦 278
2025年 春 节 306
 
您现在的位置:首页 >> PHP >> 内容
本类新增
本类热门
非常实用的php验证码类
内容摘要: ?php/****@authorAdministrator**/classValidateCode{private$width;private$height;private$codeNum;private$img_resouce;private$disturbColorNum;private$checkCode;function__construct($wi......
<?php

/**

*

*@authorAdministrator

*

*/

classValidateCode{

private$width;

private$height;

private$codeNum;

private$img_resouce;

private$disturbColorNum;

private$checkCode;

function__construct($width=80,$height=20,$codeNum=4){

$this->width=$width;

$this->height=$height;

$this->codeNum=$codeNum;

$this->checkCode=$this->CreateCheckCode();

$number=floor($width*$height/25);

if($number>240-$codeNum){

$this->disturbColorNum=240-$codeNum;

}else{

$this->disturbColorNum=$number;

}

}

publicfunctionshowImage($fontpath=''){

//创建图像背景

$this->Img_resouce();

//var_dump($img_resouce);

//设置干扰元素

$this->setDistructcolor();

//向图像中随机画出文本

$this->outputtext($fontpath);

//输出图像

$this->outputimage();

}

/**

*

*获取随机创建的验证码

*/

publicfunctiongetCheckCode(){

}

privatefunctionImg_resouce(){

//创建一个真彩图像

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

//随机设置图像背景

$backcolor=imagecolorallocate($this->img_resouce,rand(225,255),rand(225,255),rand(225,255));

//填充颜色

imagefill($this->img_resouce,0,0,$backcolor);

//设置边框背景

$border=imagecolorallocate($this->img_resouce,0,0,0);

//画一个矩形

imagerectangle($this->img_resouce,0,0,$this->width-1,$this->height-1,$border);

}

privatefunctionsetDistructcolor(){

//绘画干扰点

for($i=0;$i<$this->disturbColorNum;$i++){

imagesetpixel($this->img_resouce,rand(1,$this->width-2),rand(1,$this->height-2),rand(0,255));

}

//绘画干扰线

for($j=0;$j<3;$j++){

$linecolor=imagecolorallocate($this->img_resouce,rand(0,255),rand(0,255),rand(0,255));

imagearc($this->img_resouce,rand(0,$this->width),rand(0,$this->height),

rand(10,225),rand(20,150),

55,44,$linecolor);

}

}

privatefunctionCreateCheckCode(){

$code='23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ';

$string='';

for($i=0;$i<$this->codeNum;$i++){

$char=$code{rand(0,strlen($code)-1)};

$string.=$char;

}

return$string;

}

privatefunctionoutputtext($fontpath=''){

for($i=0;$i<$this->codeNum;$i++){

$fontcolor=imagecolorallocate($this->img_resouce,rand(0,128),rand(0,128),rand(0,128));

if($fontpath==''){

$fontsize=rand(3,5);

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

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

imagechar($this->img_resouce,$fontsize,$x,$y,$this->checkCode{$i},$fontcolor);

}else{

$fontsize=rand(12,16);

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

$y=rand($fontsize,$this->height-15);

imagettftext($this->img_resouce,$fontsize,rand(-45,45),$x,$y,$fontcolor,fontpath,$this->checkCode{$i});

}

}

}

privatefunctionoutputimage(){

if(imagetypes()&IMG_GIF){

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

imagegif($this->img_resouce);

}elseif(imagetypes()&IMG_JPEG){

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

imagejpeg($this->img_resouce);

}elseif(imagetypes()&IMG_PNG){

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

imagepng($this->img_resouce);

}else{

echo"PHP不支持的类型";

}

}

privatefunction__destruct(){

imagedestroy($this->img_resouce);

}

}

?>

版权声明:本内容来源于互联网,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:php 字符串中是否包含指定字符串的多种方法

 

下一篇:PHP ip相关知识

发布日期:2022/3/28
手机扫二维码直达本页
发布时间:19:12:44
点  击:9
录  入:壹家怡园
相关文章
Baidu
YiJiaCMS 7.3.8 build231228(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,Cloudflare提供加速防护
运行时间载入中.....