PHP Implementation Generation Verification code instance sharing, PHP verification code instance Sharing _php Tutorial

Source: Internet
Author: User

PHP implementation generated Verification code instance sharing, PHP verification code instance sharing


image.func.php

<?php require_once (' string.func.php ');  function Verifyimage ($type =1, $length =4, $pixel =0, $line =0, $sess _name= "verify") {session_start (); /* Define length and Width */$width =80; $height =30;/* Create canvas */$image =imagecreatetruecolor ($width, $height); /* This function is used to match the color of the graphic for use by other drawing functions. The parameter image represents the handle of the graph. Parameters red, green, blue are the three primary colors of the color, the value from 0 to 255 .... I hereby define black and white */$white =imagecolorallocate ($image, 255, 255, 255); $black = Imagecolorallocate ($image, 0,0,0); /* This function shades the enclosing rectangular area of the picture. The Parameters x1, y1, and x2, and Y2 are the coordinates of the rectangular diagonal respectively. The parameter col represents the color to be painted */imagefilledrectangle ($image, 1, 1, $width-2, $height-2, $white); The/*buildrandomstring function is used to generate a verification code */$chars =buildrandomstring ($type, $length); /* Pass the verification code to the SESSION to determine if the user input is correct */$_session[$sess _name]= $chars; /* Define Font Library */$fontfiles =array (' Msyh.ttf ', ' Msyhbd.ttf ', ' SIMSUN.TTC ', ' simyou. TTF ', ' Sthupo. TTF ', ' Stkaiti. TTF ', ' Stliti.  TTF ');  /* */FOR ($i =0; $i < $length; $i + +) {$size =mt_rand (14,18) with a loop to write the code one at a)   $angle =mt_rand ( -15,15);  /* The horizontal and vertical coordinates of the verification code */$x =5+ $i * $size;   $y =mt_rand (20,26); $color =imagecolorallocate ($image, Mt_rand (50, Mt_rand (50,200), Mt_rand (50,90)); $fontfile = ".  /font/". $fontfiles [Mt_rand (0,count ($fontfiles)-1)];   $text =substr ($chars, $i, 1); /* This function writes TTF (TrueType Fonts) font text to the picture */Imagettftext ($image, $size, $angle, $x, $y, $color, $fontfile, $text);} if ($pixel) {for ($i =0; $i <50; $i + +) {/* This function can draw a point on the picture. The parameter x, y is the coordinate of the plot point, and the parameter col represents the color of the point */Imagesetpixel ($image, Mt_rand (0, $width-1), Mt_rand (0, $height-1), $black);}} if ($line) {for ($i =0; $i <10; $i + +) {$color =imagecolorallocate ($image, Mt_rand (50,90), Mt_rand (50,200), Mt_rand (  50,90)); /* Draw Segment */Imageline ($image, Mt_rand (0, $width-1), Mt_rand (0, $height-1), Mt_rand (0, $width-1), Mt_rand (0, $height-1), $ color);}} /* Output */header ("Content-type:image/gif") in GIF format,/* Create a GIF graph and output to Web page */imagegif ($image);/* releases memory associated with image */imagedestroy ($ image);}

string.func.php

<?php function  buildrandomstring ($type =1, $length =4) {if ($type ==1) {  /*join functions convert the array to a string: The join () function is an alias for the implode () function */  $chars =join ("", Range (0,9));} ElseIf ($type ==2) {  /*array_merge function Merge array */  $chars =join ("", Array_merge (Range ("A", "Z"), Range ("A", "Z")));} ElseIf ($type ==3) {$chars =join ("", Array_merge (Range ("A", "Z"), Range (  "a", "Z"), Range (0,9)));} if ($length > Strlen ($chars)) {  exit ("insufficient string Length");} /* Scrambled String */$chars =str_shuffle ($chars); return substr ($chars, 0, $length); }?>

Articles you may be interested in:

    • PHP Image Captcha Code
    • PHP dynamic random Generation code for verification code
    • PHP Verification Code Class code (the latest modification, fully customizable!)
    • A nice PHP verification code class (share)
    • A workaround for "The image cannot be displayed because of its own error" when PHP generates a verification code
    • PHP Generate image Verification code, click to switch instances
    • PHP Generate Captcha function
    • thinkphp3.2 Click Refresh to generate the verification code
    • PHP generated verification code, thumbnails and Watermark class sharing

http://www.bkjia.com/PHPjc/1119980.html www.bkjia.com true http://www.bkjia.com/PHPjc/1119980.html techarticle PHP Implementation generated verification code instance sharing, PHP verification code instance sharing image.func.php PHP require_once (' string.func.php '); function verifyimage ($type =1,$ length=4, $pixel =0, $line =0, $sess _n ...

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