gpt4 book ai didi

PHP生成图片验证码功能示例

转载 作者:qq735679552 更新时间:2022-09-27 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章PHP生成图片验证码功能示例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

本文实例讲述了PHP生成图片验证码功能。分享给大家供大家参考,具体如下:

只是简单的用随机函数实现了图片的生成,没有对验证的整个流程做介绍.

代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
  * Created by JetBrains PhpStorm.
  * User: lee
  * To change this template use File | Settings | File Templates.
  */
header( "content-type:image/png" );
$validateLength =4;
$strToDraw = "" ;
$chars =[
   "0" , "1" , "2" , "3" , "4" ,
   "5" , "6" , "7" , "8" , "9" ,
   "a" , "b" , "c" , "d" , "e" , "f" , "g" ,
   "h" , "i" , "j" , "k" , "l" , "m" , "n" ,
   "o" , "p" , "q" , "r" , "s" , "t" ,
   "u" , "v" , "w" , "x" , "y" , "z" ,
   "A" , "B" , "C" , "D" , "E" , "F" , "G" ,
   "H" , "I" , "J" , "K" , "L" , "M" , "N" ,
   "O" , "P" , "Q" , "R" , "S" , "T" ,
   "U" , "V" , "W" , "X" , "Y" , "Z"
];
$imgW =80;
$imgH =25;
$imgRes =imagecreate( $imgW , $imgH );
$imgColor =imagecolorallocate( $imgRes ,255,255,100);
$color =imagecolorallocate( $imgRes ,0,0,0);
for ( $i =0; $i < $validateLength ; $i ++){
   $rand =rand(1,58);
   $strToDraw = $strToDraw . " " . $chars [ $rand ];
}
imagestring( $imgRes ,5,0,5, $strToDraw , $color );
for ( $i =0; $i <100; $i ++){
   imagesetpixel( $imgRes ,rand(0, $imgW ),rand(0, $imgH ), $color );
}
imagepng( $imgRes );
imagedestroy( $imgRes );

运行效果如下:

PHP生成图片验证码功能示例

希望本文所述对大家PHP程序设计有所帮助.

最后此篇关于PHP生成图片验证码功能示例的文章就讲到这里了,如果你想了解更多关于PHP生成图片验证码功能示例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com