- Untitled Document
Copy Code
The verifycode.php file code is as follows
- /*
- Image verification Code Powered by Kason Test http://www.hzhuti.com/nokia/c6/*/
- 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
- ?>
Copy Code
checkcode.php files are as follows
- 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"]);
- ?>
Copy Code
|