PHP generated verification code and Verification Code verification complete instance

Source: Internet
Author: User

Title Document

<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >  xmlns= "http://www.w3.org/1999/xhtml" >  http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/> <title> Untitled document </title> <script language= "JavaScript" > Function Refresh_code () {form1.imgcode.src= "verifycode.php?a=" +math.random (); } </script>  Id= "Form1" Name= "Form1" method= "Post" action= "checkcode.php" > <label For= "Code" > Verification Code:</label> <input Type= "text" name= "code" id= "TextField"/>  Id= "Imgcode" src= "verifycode.php" alt= "Verification Code"/> <a Href= "Javascript:refresh_code ()" > Can't see clearly? Change a </a> <input Type= "Submit" name= "button" id= "button" value= "Submit"/> </form> </body>

The verifycode.php file code is as follows

<?php/* Picture Verification Code Powered by Kason test <a href= "http://www.hzhuti.com/nokia/c6/" > Http://www.hzhuti.com/nokia/c   6/</a> */session_start ();   $num =4;//Verification Code number $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;//Digital 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 characters 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

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 " /> <?php ini_set (' display_errors ', ' Off ');   Session_Start ();   if ((Strtoupper ($_post["code")) ==strtoupper (($_session["Verifycode"])) {print ("captcha correct,");   }else{Print ("Captcha error,"); } Echo "submitted Captcha:". Strtoupper ($_post["code"]). ", correct captcha:". Strtoupper ($_session["Verifycode"]);?>

PHP generated verification code and Verification Code verification complete instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.