-
php生成图片验证码
首先,有一个在php.ini看看gd库是不是开启的,下一步,我们会考虑每一个细节的图像生成步骤.
php生成图片验证码实例代码如下:
- <?php
- //Send a generated image to the browser
- create_image();
- exit();
- function create_image()
- {
- //Let's generate a totally random string using md5
- $md5 = md5(rand(0,999));
- //We don't need a 32 character long string so we trim it down to 5
- $pass = substr($md5, 10, 5);
- //Set the image width and height
- $width = 100;
- $height = 20;
- //Create the image resource
- $image = ImageCreate($width, $height);
- //We are making three colors, white, black and gray
- $white = ImageColorAllocate($image, 255, 255, 255);
- $black = ImageColorAllocate($image, 0, 0, 0);
- $grey = ImageColorAllocate($image, 204, 204, 204);
- //Make the background black
- ImageFill($image, 0, 0, $black);
- //Add randomly generated string in white to the image
- ImageString($image, 3, 30, 3, $pass, $white);
- //Throw in some lines to make it a little bit harder for any bots to
- break
- ImageRectangle($image,0,0,$width-1,$height-1,$grey);
- imageline($image, 0, $height/2, $width, $height/2, $grey);
- imageline($image, $width/2, 0, $width/2, $height, $grey);
- //Tell the browser what kind of file is come in
- header("Content-Type: image/jpeg");
- //开源代码phpfensi.com
- //Output the newly created image in jpeg format
- ImageJpeg($image);
- //Free up resources
- ImageDestroy($image);
- }
- ?>
验证码调用方法,代码如下:
<img height="120" alt="Dynamically generated image" src="generate_image.php" width="200">
原文链接:http://www.phpfensi.com/php/20140825/4754.html
栏目列表
最新更新
Java编程的逻辑-面向对象
深入浅出 JAXB:自定义映射方式
Golang与Java的区别
Python第三方模块安装方法
Python常用模块之OS使用
python如何发送邮件(zmail模块)
Python中什么是类?如何定义?
Python使用xlrd读取Excel
Python使用xlrd写入Excel
go语言学习笔记-初识Go语言
三大常用数据库事务详解之三:事务运行
三大常用关系型数据库事务详解之二:基
三大关系型数据库事务详解之一:基本概
MongoDB常用命令(2)
MongoDB基本介绍与安装(1)
SQLServer触发器调用JavaWeb接口
SQL Server索引的原理深入解析
SqlServer2016模糊匹配的三种方式及效率问题
SQL中Truncate的用法
sqlserver 多表关联时在where语句中慎用tri
VB.NET中如何快速访问注册表
ASP.NET中图象处理过程详解
Vue(1)Vue安装与使用
JavaScript 语言入门
js将一段字符串的首字母转成大写
纯原生html编写的h5视频播放器
H5仿原生app短信验证码vue2.0组件附源码地
TypeScript(4)接口
TypeScript(3)基础类型
TypeScript(2)WebStorm自动编译TypeScript配置