Goal: Generate a verification code using PHP
Finished:
Logic code: authcode.php
<?PHPHeader("Content-type:image/png");Session_Start();//$str used to store verification codes$str="";//0,o,1,l and other easily confusing characters are removed from the $charset$cs= "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ2345678923456789";$img=imagecreate ($width=100,$height=26);//picture background color using light tones$img _BG=imagecolorallocate ($img,Rand(186,255),Rand(186,255),Rand(186,255)); for($i= 0;$i<4;++$i){ //text color using dark tones $txt _color=imagecolorallocate ($img,Rand(0,86),Rand(0,86),Rand(0,86)); //Random one character from the $charset $tmp=substr($cs,Rand(0,strlen($cs)-1), 1); //to offset and displayImagestring ($img, 5,$i*24+Rand(6,15),Rand(2,12),$tmp,$txt _color); $str.=$tmp;}//put the CAPTCHA value in the session for later use (verify user input verification code)$_session["Authcode"]=$str;//Add a background line for($j= 0;$j<5;++$j){ $line _color=imagecolorallocate ($img,Rand(150,210),Rand(150,210),Rand(150,210)); Imageline ($img,Rand(0,$width),Rand(0,$height),Rand(0,$width),Rand(0,$height),$line _color);}//Add a noise point for($i= 0;$i<250;++$i){ $img _noisy=imagecolorallocate ($img,Rand(150,210),Rand(150,210),Rand(150,210)); Imagesetpixel ($img,Rand(0,$width),Rand(0,$height),$img _noisy);} Imagepng ($img); Imagedestroy ($img);
Front End use: register.html
PHP Verification Code Production