Home > Backend Development > PHP Tutorial > Generate verification code in php_PHP tutorial

Generate verification code in php_PHP tutorial

WBOY
Release: 2016-07-13 10:59:19
Original
787 people have browsed it

Please indicate the source of original reprints on this site


session_start();


header("content-type:image/png"); Set the format of the generated image here as png


$width=40;//Width


$height=25;//Height


$color="#ffffff";//Color


$num=rand(1000,9999);//Generate a 4-digit random number


$_SESSION['ver']=$num; Verify before saving to session


$img=imagecreate($width,$height);//Use imagecreate to create images


$bg1=imagecolorallocate($img,rand(0,100),rand(0,250),rand(0,255));//Picture color


$bg2=imagecolorallocate($img,rand(0,205),rand(0,250),rand(0,245));


//imageline($img,40,20,40,40,$color);


//imagesetpixel($img,44,44,$color);


imagestring($img,7,4,7,$num,$bg2);//Increase noise


imagepng($img);//Generate image


imagedestroy($img);//Destroy


?>

This is very simple, so I won’t go into details.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631907.htmlTechArticlePlease indicate the source of original reprints on this site?php session_start(); header(content-type:image/png );Set the format of the generated image here as png $width=40; //Width $height=25; //Height $color=#ffffff...
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