This article to share a self-used verification code instance, from the generation of picture verification code to the use of examples of using verification code, there are students who need to learn to refer to this article Oh.
Hyml page
The code is as follows |
Copy Code |
Untitled Document
|
The verifycode.php file code is as follows
The code is as follows |
Copy Code |
/* Image verification Code Powered by Kason */ Session_Start (); $num =4;//number of verification codes $width =80;//Verification Code width $height =20;//Verification Code height $code = "; for ($i =0; $i < $num; $i + +)//Generate Verification code { Switch (rand (0,2)) { Case 0: $code [$i]=CHR (rand (48,57)); break;//number Case 1: $code [$i]=CHR (rand (65,90)); break;//Capital Letter Case 2: $code [$i]=CHR (rand (97,122)); break;//Small Letter } } $_session["Verifycode"]= $code; $image =imagecreate ($width, $height); Imagecolorallocate ($image, 255,255,255); for ($i =0; $i <80; $i + +)//Generate interference pixels { $dis _color=imagecolorallocate ($image, Rand (0,2555), Rand (0,255), Rand (0,255)); Imagesetpixel ($image, rand (1, $width), rand (1, $height), $dis _color); } for ($i =0; $i < $num; $i + +)//print character to image { $char _color=imagecolorallocate ($image, Rand (0,2555), Rand (0,255), Rand (0,255)); Imagechar ($image, Max, ($width/$num) * $i, Rand (0,5), $code [$i], $char _color); } Header ("Content-type:image/png"); Imagepng ($image);//output image to browser Imagedestroy ($image);//Release resources ?> |
checkcode.php files are as follows
The code is as follows |
Copy Code |
Ini_set (' display_errors ', ' Off '); Session_Start (); if ((Strtoupper ($_post["code")) = = Strtoupper (($_session["Verifycode"])) { Print ("Verification code is correct,"); }else{ Print ("Captcha error,"); } echo "submitted Captcha:". Strtoupper ($_post["code"]). ", correct captcha:". Strtoupper ($_session["Verifycode"]); ?> |
http://www.bkjia.com/PHPjc/631291.html www.bkjia.com true http://www.bkjia.com/PHPjc/631291.html techarticle This article to share a self-used verification code instance, from the generation of picture verification code to the use of examples of using verification code, there are students who need to learn to refer to this article Oh. Hyml page ...