This article mainly introduces how php implements an operational verification code. the code is very detailed and worth learning, if you are interested, you can refer to this article to share the code example for php code to implement an operational verification code. I hope it will be helpful for your learning.
Demo. php code
<?php session_start(); if(!emptyempty($_POST['Login'])){ if(md5(strtoupper($_POST['Login'])) == $_SESSION['Login']){ echo 'Correct'; }else{ echo 'Error'; } } ?>
Img. php code
<? Php session_start ();/*** random number, sum verification code * modification date */function getCode ($ length = 32, $ mode = 0) {switch ($ mode) {case '1': $ str = '000000'; break; case '2': $ str = 'abcdefghijklmnopqrstuvwxyz '; break; case '3 ': $ str = 'abcdefghijklmnopqrstuvwxy'; break; case '4': $ str = 'authorization'; break; case '5': $ str = 'abcdefghijklmnpqrstuvwxyz123456789 '; Break; case '6': $ str = 'abcdefghijklmnopqrstuvwxyz1234567890 '; break; default: $ str = 'authorization'; break;} $ result = ''; $ l = strlen ($ str)-1; for ($ I = 0; $ I <$ length; $ I ++) {$ num = rand (0, $ l); $ result. = $ str [$ num];} return $ result;} // Create a verification image function createAuthNumImg ($ randStr, $ imgW = 100, $ imgH = 40, $ fontName) {header ("content-type: image/png "); $ Image = imagecreate ($ imgW, $ imgH); $ color_white = imagecolorallocate ($ image, 255,255,255); $ color_gray = imagecolorallocate ($ image, 228,228,228 ); $ color_black = imagecolorallocate ($ image, 255,102,204); for ($ I = 0; $ I <1000; $ I ++) {imagesetpixel ($ image, mt_rand (0, $ imgW), mt_rand (0, $ imgH), $ color_gray);} imagerectangle ($ image, 0, 0, $ imgW-1, $ imgH-1, $ color_gr Ay); for ($ I = 10; $ I <$ imgH; $ I + = 10) imageline ($ image, 0, $ I, $ imgW, $ I, $ color_gray); imagettftext ($ image, 16,5, 3,25, $ color_black, $ fontName, $ randStr); for ($ I = 10; $ I <$ imgW; $ I + = 10) imageline ($ image, $ I, 0, $ I, $ imgH, $ color_gray); imagepng ($ image); imagedestroy ($ image );} $ a = GetCode (1, 1); $ B = GetCode (1, 1); $ c = GetCode (1, 1); $ Passport = $. "+ ". $ B. "+ ". $ c; $ Total = $ a + $ B + $ c; $ Total; $ _ SESSION [$ _ GET ['action'] = md 5 (strtoupper ($ Total); createAuthNumImg ($ Passport, $ _ GET ['img'], $ _ GET ['imgh'], "verdana. ttf ");?>
The above is all the codes of php verifiable verification codes introduced to everyone. I hope this will help you learn more.