Home > Backend Development > PHP Tutorial > php simple verification code

php simple verification code

WBOY
Release: 2016-07-29 09:04:49
Original
1100 people have browsed it

Use php to generate digital verification code

$img = imagecreatetruecolor(100, 40);
$black = imagecolorallocate($img, 0x00, 0x00, 0x00);
$green = imagecolorallocate($img, 0x00, 0xFF, 0x00);
$white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
imagefill($img,0,0,$white);
//Generate a random verification code
$code = ' ';
for($i = 0; $i < 4; $i++) {
$code .= rand(0, 9);
}
imagestring($img, 5, 10, 10, $code, $ black);
//Add noise interference
for($i=0;$i<50;$i++) {
imagesetpixel($img, rand(0, 100) , rand(0, 100) , $black);
imagesetpixel($img, rand(0, 100) , rand(0, 100) , $green);
}
//Output verification code
header("content-type: image/png");
imagepng($ img);
imagedestroy($img);

The above introduces the PHP simple verification code, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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