Support for Chinese, Alphabet, and digital php captcha _php instances

Source: Internet
Author: User
In this paper, we demonstrate 5 kinds of verification codes, and describe the function of generating verification code. PHP generated Verification code principle: Through the GD library, generate a picture with a verification code, and save the Verification code in the session.

Session_Start ();   GetCode (4,60,20);   function GetCode ($num, $w, $h) {$code = "";   for ($i = 0; $i < $num; $i + +) {$code. = rand (0, 9);   }//4-bit verification code can also be generated directly with Rand (1000,9999)//The generated verification code is written to the SESSION, the verification with $_session["helloweba_num"] = $code;   Create a picture, define the color value header ("Content-type:image/png");   $im = Imagecreate ($w, $h);   $black = imagecolorallocate ($im, 0, 0, 0);   $gray = Imagecolorallocate ($im, 200, 200, 200);   $bgcolor = Imagecolorallocate ($im, 255, 255, 255);     Fill Background imagefill ($im, 0, 0, $gray);     Draw Border Imagerectangle ($im, 0, 0, $w-1, $h-1, $black);   Randomly draws two dashed lines, acts as a disturbance $style = Array ($black, $black, $black, $black, $black, $gray, $gray, $gray, $gray, $gray);   Imagesetstyle ($im, $style);   $y 1 = rand (0, $h);   $y 2 = rand (0, $h);   $y 3 = rand (0, $h);   $y 4 = rand (0, $h);   Imageline ($im, 0, $y 1, $w, $y 3, img_color_styled);     Imageline ($im, 0, $y 2, $w, $y 4, img_color_styled);   A large number of black dots are randomly generated on the canvas, which acts as interference; for ($i = 0; $i < $i + +) {Imagesetpixel ($im, rand (0,$W), rand (0, $h), $black);   The numbers are randomly displayed on the canvas, and the horizontal spacing and position of the characters are randomly generated according to a certain range of fluctuations $strx = rand (3, 8);     for ($i = 0; $i < $num; $i + +) {$strpos = rand (1, 6);     Imagestring ($im, 5, $strx, $strpos, substr ($code, $i, 1), $black);   $strx + = rand (8, 12); } imagepng ($im);//Output Picture Imagedestroy ($im);//release Image Memory}

The above mentioned is the whole content of this article, I hope you can like.

  • 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.