We know that the verification code is a picture, but PHP itself does not support the processing of images, need to rely on the GD library.
Let's take a look at the use of the GD Library to implement verification code production:
Look directly at the code ~
<?php
Make Verification Code
$im =imagecreatetruecolor (200,50);
Create a background color
$color =imagecolorallocate ($im, Mt_rand (200,255), Mt_rand (200,255), Mt_rand (200,255));
Fill Canvas
Imagefill ($im, 0,0, $color);
Get Authenticode Data
$str = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789 ';
$captcha = ";
for ($i =0; $i <5; $i + +)
{
$captcha. = $str [Mt_rand (0,strlen ($STR)-1)];
}
Set Text color
$str _color=imagecolorallocate ($im, Mt_rand (0,100), Mt_rand (0,100), Mt_rand (0,100));
Write text to a picture
Imagestring ($im, 5,80,20, $captcha, $str _color);
Increase the interference line (to the top of the word)
for ($j =0; $j <5; $j + +)
{
$line _color=imagecolorallocate ($im, Mt_rand (100,200), Mt_rand (100,200), Mt_rand (100,200));
Crossed
Imageline ($im, Mt_rand (0,200), Mt_rand (0,50), Mt_rand (0,200), Mt_rand (0,50), $line _color);
}
Draw points
for ($i =0; $i <300; $i + +)
{
$line _pixel=imagecolorallocate ($im, Mt_rand (100,200), Mt_rand (100,200), Mt_rand (100,200));
Imagesetpixel ($im, Mt_rand (0,200), Mt_rand (0,50), $line _pixel);
}
Header (' content-type:image/png ');
Imagepng ($im);
PHP Production Verification Code