Home > Backend Development > PHP Problem > Learn about encapsulating verification codes in PHP in one minute (Part 2)

Learn about encapsulating verification codes in PHP in one minute (Part 2)

慕斯
Release: 2023-03-10 21:48:02
Original
1775 people have browsed it

PHP中我们了解了那么多关于php的知识,不知道你们对封装验证码有多少了解,我相信很大一部分人会不知道这部分知识点,那么不急本篇文章就是带领大家更深刻的去了解这个内容。

相关推荐:一分钟学会PHP中关于封装验证码(上)

关于封装验证码下:

首先我们先新建一个文件,然后写上他们的条件,宽,高,字母,数字,字母数字混合,干扰点,背景色,字体颜色等;紧接着我们定义一个函数,然后,我们开始准备画布,生成颜色,以及我们所需要的什么样的字符,干扰点和准备输出的类型,准备输出的图片到最后的销毁;

具体代码如下:

//4开始写字

for($i=0;$i<$num;$i++){
  $x =floor ($width / $num) *$i;
  $y= mt_rand(10 ,$height - 20) ;
  imagechar($image,5,$x ,$y,$string[$i] ,deepColor ()) ;
}
Copy after login

//5干扰线(点)

for ($i = 0; $i<$num ; $i++) (
  imagearc ($image,mt_rand(10 ,$width) ,mt_rand(10 ,$height) ,mt_rand(10 ,$width) ,
  mt_rand(10,$height) ,mt_rand(0,10),mt_rand(0,270) ,deepColor($image));
}
for ($1 =0; $i<50 ; $1++){
imagesetpixel ($image,mt_rand(O,$width) ,mt_rand(0 ,$height) ,deepColor ($image)) ;
}
Copy after login

//6指定输出的类型

header (&#39;Content - type : image/png&#39; ) ;
Copy after login

//7准备输出图片

imagepng ($image) ;
Copy after login

//8 销毁

imagedestroy ($image) ;
return $string;
}
Copy after login

根据以上我们代码演示,我们需要去建立他们的规格,颜色以及我们所需要的字符样式等等;

相关学习视频分享:php视频教程

The above is the detailed content of Learn about encapsulating verification codes in PHP in one minute (Part 2). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template