0

0

验证码类,php验证码类_PHP教程

php中文网

php中文网

发布时间:2016-07-12 09:06:54

|

1372人浏览过

|

来源于php中文网

原创

验证码类,php验证码类

熟悉相关图像处理函数,简单的验证码类    


1
//code class 2 class ValidateCode { 3 private $charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789'; //random effects 4 private $code; //code 5 private $codelen = 4 ; //code length 6 private $width = 130; //width 7 private $heigth = 50; //height 8 private $img; //image handle 9 private $font; //font file 10 private $fontsize = 20; //font size 11 private $fontcolor; //font color 12 13 //the construct initialization 14 public function __construct(){ 15 $this->font = ROOT_PATH.'/font/elephant.ttf'; 16 } 17 18 //create random code from $charset 19 private function createCode(){ 20 $_len = strlen($this->charset); 21 for($i=1;$i<=$this->codelen;$i++){ 22 $this->code .= $this->charset[mt_rand(0,$_len)]; 23 } 24 } 25 26 //create background 27 private function createBg(){ 28 $this->img = imagecreatetruecolor($this->width, $this->heigth); 29 $_color = imagecolorallocate($this->img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255)); 30 imagefilledrectangle($this->img,0,0,$this->width,$this->heigth,$_color); 31 } 32 33 //create font 34 private function createFont(){ 35 $_x = $this->width / $this->codelen; 36 for($i=0;$i<$this->codelen;$i++){ 37 $this->fontcolor = imagecolorallocate($this->img, mt_rand(0,156), mt_rand(0,156), mt_rand(0,156)); 38 imagettftext($this->img, $this->fontsize, mt_rand(-30,30), $_x*$i+mt_rand(1,5), $this->heigth/1.4, $this->fontcolor, $this->font, $this->code[$i]); 39 } 40 } 41 42 //create line,snowflake 43 private function createLine(){ 44 for($i=0;$i<6;$i++){ 45 $_color = imagecolorallocate($this->img, mt_rand(0,156), mt_rand(0,156), mt_rand(0,156)); 46 imageline($this->img, mt_rand(0,$this->width), mt_rand(0, $this->heigth),mt_rand(0,$this->width), mt_rand(0, $this->heigth), $_color); 47 } 48 for($i=0;$i<100;$i++){ 49 $_color = imagecolorallocate($this->img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255)); 50 imagestring($this->img, mt_rand(1, 5), mt_rand(0,$this->width), mt_rand(0,$this->heigth), '*', $_color); 51 } 52 } 53 54 //export image 55 private function outPut(){ 56 header('Content-type:image/png'); 57 imagepng($this->img); 58 imagedestroy($this->img); 59 } 60 61 //display 62 public function doimg(){ 63 $this->createBg(); 64 $this->createCode(); 65 $this->createLine(); 66 $this->createFont(); 67 $this->outPut(); 68 } 69 70 //get code 71 public function getCode(){ 72 return strtolower($this->code); 73 } 74 75 } 76

 

思高数码广场
思高数码广场

修订记录:1.用户登陆增加了验证码,提高了安全性,登陆后不再显示登陆框。2.修改成了相对路径,不再一定需要放置在网站根目录下面。3.修改了类别搜索功能,并且可以暂时屏蔽,而不是删除,修改了先增加大类后出现无法修改中类名称的bug。4.增加了产品修改,可以保存修改。5.原来是借用别人的流量统计系统,不能统计某个页面的访问量,现采用的count.seecool.net的流量统计。6.帮助中心采用了fa

下载

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1063511.htmlTechArticle验证码类,php验证码类 熟悉相关图像处理函数,简单的验证码类 1 // code class 2 class ValidateCode { 3 private $charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNP...

相关文章

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

相关标签:

php

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

2

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

2

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

0

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

29

2025.12.24

yandex外贸入口合集
yandex外贸入口合集

本专题汇总了yandex外贸入口地址,阅读下面的文章了解更多内容。

58

2025.12.24

添加脚注通用方法
添加脚注通用方法

本专题整合了添加脚注方法合集,阅读专题下面的文章了解更多内容。

1

2025.12.24

重启电脑教程汇总
重启电脑教程汇总

本专题整合了重启电脑操作教程,阅读下面的文章了解更多详细教程。

3

2025.12.24

纸张尺寸汇总
纸张尺寸汇总

本专题整合了纸张尺寸相关内容,阅读专题下面的文章了解更多内容。

5

2025.12.24

Java Spring Boot 微服务实战
Java Spring Boot 微服务实战

本专题深入讲解 Java Spring Boot 在微服务架构中的应用,内容涵盖服务注册与发现、REST API开发、配置中心、负载均衡、熔断与限流、日志与监控。通过实际项目案例(如电商订单系统),帮助开发者掌握 从单体应用迁移到高可用微服务系统的完整流程与实战能力。

1

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
PostgreSQL 教程
PostgreSQL 教程

共48课时 | 5.9万人学习

Git 教程
Git 教程

共21课时 | 2.2万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号