PHP development verification code tutorial to implement digital verification code
Implementing digital verification code
<?php
$image = imagecreatetruecolor(100,30);
$bgcolor = imagecolorallocate($image,255,255,255);//#FFFFFFFFFFFF
imagefill($image,0,0,$bgcolor);
for ($i=0;$i<4;$i++){
$fontsize = 6;
$fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
$fontcontent = rand(0,9);
$x = ($i * 100/4)+rand(5,10);
$y = rand(5,10);
imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}
header('content-type: image/png');
imagepng($image);
//销毁
imagedestroy($image);
?>for ($i=0;$i<4;$i++){
//循环出四个数字
$fontsize = 6;//字体的大小为6
$fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
//定义字体的颜色
$fontcontent = rand(0,9);//定义字体的取值范围
}$x = ($i * 100/4)+rand(5,10);
$y = rand(5,10);
在范围内随机定义坐标
imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}imagestring() uses col color to draw the string s to x of the image represented by image, y coordinate (this is the coordinate of the upper left corner of the string, the upper left corner of the entire image is 0, 0). If font is 1, 2, 3, 4 or 5, the built-in font is used.
Note: Control the size and distribution of fonts to avoid overlapping and incomplete display of fonts
new file
<?php
$image = imagecreatetruecolor(100,30);
$bgcolor = imagecolorallocate($image,255,255,255);//#FFFFFFFFFFFF
imagefill($image,0,0,$bgcolor);
for ($i=0;$i<4;$i++){
$fontsize = 6;
$fontcolor = imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));
$fontcontent = rand(0,9);
$x = ($i * 100/4)+rand(5,10);
$y = rand(5,10);
imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}
header('content-type: image/png');
imagepng($image);
//销毁
imagedestroy($image);
?>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















