Home > Backend Development > PHP Tutorial > Detailed tutorial on generating verification code in php_PHP tutorial

Detailed tutorial on generating verification code in php_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:45:36
Original
858 people have browsed it

This article provides a detailed tutorial on generating verification codes in PHP. The first part is about generating the core verification code, and the second part is a method of generating and calling it.

//header("content-type:image/png");
$num ='1234';
$imagewidth=60;
$imageheight=18;

$numimage = imagecreate($imagewidth,$imageheight);
imagecolorallocate($numimage,240,240,240);
for($i=0;$i $x = mt_rand(1,8)+$imagewidth*$i/4;
$y = mt_rand(1,$imageheight/4);
$color=imagecolorallocate($numimage,mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
imagestring($numimage,5,$x,$y,$num[$i],$color);
}

for($i=0;$i<200;$i++){
$randcolor=imagecolorallocate($numimage,rand(200,255),rand(200,255),rand(200,255));
imagesetpixel($numimage,rand()%70,rand()%20,$randcolor);
}
imagepng($numimage);
imagedestroy($numimage);
?>


Let’s take a look at an example of generating a verification code

//Generate verification code image

session_start();

header("content-type: image/png");

srand((double)microtime()*1000000);

$roundnum=rand(1000,9999);

//Save the random number into the session for later use

$_session["sessionround"]=$roundnum;

$im = imagecreate(58,28);

$red = imagecolorallocate($im, 255,0,0);

$blue = imagecolorallocate($im, 0,255,0);

//Local filling, equivalent to background

imagefill($im,68,30,$red);

//Draw the four-digit integer verification code into the picture

imagestring($im, 5, 10, 8, $roundnum, $blue);

for($i=0;$i<50;$i++) //Add interference pixels

          {

imagesetpixel($im, rand()%70, rand()%30, $black);

}

imagepng($im);

imagedestroy($im);

?>


html call method

Verification code

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633006.htmlTechArticleThis article provides a detailed tutorial on generating verification codes in PHP. The first part is about generating the verification core code, and the following is A method to generate and call. ?php //header(content-type:image...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template