0

0

php简略验证码

php中文网

php中文网

发布时间:2016-06-13 10:30:16

|

1002人浏览过

|

来源于php中文网

原创

php简单验证码
     
     
         
    class VerifyImg { 
        public $fontSize = 15; //定义字体大小 
        public $length = 4; //定义字符串长度                         
        public $width = 70; //定义图片宽度 
        public $height = 30; //定义图片高度 
        public $im = null; //生成一张指定宽高的图片 
        public $font = 'C:/Windows/Fonts/Arial.TTF'; 
        public $strNum = ""; 
        public function Build() { 
            $strings = Array ('1', '2','3', '4', '5', '6', '7', 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y' ); 
    //      $strNum = ""; 
            $count = count ( $strings ); 
            for($i = 1; $i length; $i ++) { //循环随机取字符生成字符串 
                $strNum .= $strings [rand ( 0, $count - 1 )]; 
            } 
            session_start (); 
            $_SESSION ["verifycode"] = $strNum; 
            $this->im = imagecreate ( $this->width, $this->height ); 
            $backgroundcolor = imagecolorallocate ( $this->im, 255, 255, 255 ); //生成背景色 
            $frameColor = imageColorAllocate ( $this->im, 0, 255, 0 ); 
            for($i = 0; $i length; $i ++) { 
                $charY = ($this->height + 9) / 2 + rand ( - 1, 1 ); //定义字符Y坐标 
                $charX = $i * 15 + 8; //定义字符X坐标 
                //            $text_color = imagecolorallocate($this->im, 255, 0, 0);                                                //生成字符颜色 
                $text_color = imagecolorallocate ( $this->im, mt_rand ( 50, 255 ), mt_rand ( 50, 128 ), mt_rand ( 50, 200 ) ); 
                $angle = rand ( - 20, 20 ); //生成字符角度 
                //写入字符 
                imagettftext ( $this->im, $this->fontSize, $angle, $charX, $charY, $text_color, $this->font, $strNum [$i] ); 
            } 
            for($i = 0; $i                 $linecolor = imagecolorallocate ( $this->im, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) ); 
                $linex = mt_rand ( 1, $this->width - 1 ); 
                $liney = mt_rand ( 1, $this->height - 1 ); 
                imageline ( $this->im, $linex, $liney, $linex + mt_rand ( 0, 4 ) - 2, $liney + mt_rand ( 0, 4 ) - 2, $linecolor ); 
            } 
            for($i = 0; $i                 $pointcolor = imagecolorallocate ( $this->im, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) ); 
                imagesetpixel ( $this->im, mt_rand ( 1, $this->width - 1 ), mt_rand ( 1, $this->height - 1 ), $pointcolor ); 
            } 
            imagerectangle ( $this->im, 0, 0, $this->width - 1, $this->height - 1, $frameColor ); //画边框 
            ob_clean (); 
            header ( 'Content-type:image/png' ); 
            imagepng ( $this->im ); 
            imagedestroy ( $this->im ); 
        } 
    } 
    $img = new VerifyImg (); 
    $img->Build (); 
    ?>  (fblww-0103)

相关文章

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

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

下载

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

相关专题

更多
javascript void运算符
javascript void运算符

void是一元运算符,执行右侧表达式但始终返回undefined;用于丢弃返回值、阻止a标签跳转、IIFE忽略结果、动态导入不取Promise、安全获取undefined。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

1

2025.12.29

vscode的界面字体大小调整
vscode的界面字体大小调整

调整VSCode界面字体大小可通过设置编辑器或整体UI缩放实现;2.修改"Editor:FontSize"改变代码字体;3.设置"Window:ZoomLevel"调整整体界面字体;4.使用Ctrl+滚轮快捷键临时缩放。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

1

2025.12.29

VSCode的注释快捷键
VSCode的注释快捷键

单行注释快捷键为Ctrl+/(Windows/Linux)或Cmd+/(macOS),块注释使用Shift+Alt+A(Windows/Linux)或Shift+Option+A(macOS),VSCode会根据语言类型自动匹配语法,如JavaScript用//,Python用#,C++用//,若快捷键无效需检查语言扩展或插件冲突。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

1

2025.12.29

Golang 命令行工具(CLI)开发实战
Golang 命令行工具(CLI)开发实战

本专题系统讲解 Golang 在命令行工具(CLI)开发中的实战应用,内容涵盖参数解析、子命令设计、配置文件读取、日志输出、错误处理、跨平台编译以及常用CLI库(如 Cobra、Viper)的使用方法。通过完整案例,帮助学习者掌握 使用 Go 构建专业级命令行工具与开发辅助程序的能力。

4

2025.12.29

ip地址修改教程大全
ip地址修改教程大全

本专题整合了ip地址修改教程大全,阅读下面的文章自行寻找合适的解决教程。

165

2025.12.26

压缩文件加密教程汇总
压缩文件加密教程汇总

本专题整合了压缩文件加密教程,阅读专题下面的文章了解更多详细教程。

56

2025.12.26

wifi无ip分配
wifi无ip分配

本专题整合了wifi无ip分配相关教程,阅读专题下面的文章了解更多详细教程。

108

2025.12.26

漫蛙漫画入口网址
漫蛙漫画入口网址

本专题整合了漫蛙入口网址大全,阅读下面的文章领取更多入口。

356

2025.12.26

b站看视频入口合集
b站看视频入口合集

本专题整合了b站哔哩哔哩相关入口合集,阅读下面的文章查看更多入口。

703

2025.12.26

热门下载

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

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
JavaScript高级框架设计视频教程
JavaScript高级框架设计视频教程

共22课时 | 3.5万人学习

AngularJS教程
AngularJS教程

共24课时 | 2.1万人学习

CSS3实现按钮特效视频教程
CSS3实现按钮特效视频教程

共15课时 | 3.2万人学习

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

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