A very useful verification code tool class

Source: Internet
Author: User
<无详细内容>
  1. /**
  2. * Verification Code Class
  3. */
  4. Class base_tool_verify{
  5. /**
  6. * Generate Verification Code method
  7. */
  8. public static function Createcode () {
  9. Generate a Captcha picture
  10. Full Digital
  11. $str = "D,b,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,w,j,k,m,m,n,k,p,q,r,s,t,u,v,w,x,y,z"; To display the characters, you can make additions and deletions
  12. $list = Explode (",", $str);
  13. $cmax = count ($list)-1;
  14. $verifyCode = ";
  15. for ($i =0; $i < 4; $i + +) {
  16. $randnum = Mt_rand (0, $cmax);
  17. $verifyCode. = $list [$randnum]; Take out the characters and combine them into the captcha characters we want.
  18. }
  19. $_session[' Code ' = $verifyCode; Put characters in session
  20. $im = Imagecreate (80,28); Create a picture
  21. $black = imagecolorallocate ($im, 0, 0, 0); This bar and the following three are set for the color
  22. $white = Imagecolorallocate ($im, 244,249,244);
  23. $gray = Imagecolorallocate ($im, Rand (200,255), Rand (200,255), Rand (200,255));
  24. $red = Imagecolorallocate ($im, Rand (200,255), Rand (200,255), Rand (200,255));
  25. $rand _color = Imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
  26. $rand _color2 = Imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
  27. Imagefill ($im, 0,0, $white); Fill a picture with color
  28. $pix =imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
  29. Mt_srand ();
  30. for ($i =0; $i <100; $i + +)
  31. {
  32. Imagesetpixel ($im, Mt_rand (0,180), Mt_rand (0,35), $pix);
  33. }
  34. Imageline ($im, 0,rand (0,28), N, Rand (0,28), $rand _color);
  35. Imageline ($im, 0,rand (0,28), N, Rand (0,28), $rand _color2);
  36. Draw a verification code into a picture
  37. $mycolor = imagecolorallocate ($im, 0, 78, 152);
  38. $path = Api_path. DS. ' Base '. DS. ' Tool ';
  39. Putenv (' gdfontpath= '. $path);
  40. $font = ' Simhei.ttf ';
  41. $arrstr = Str_split ($verifyCode);
  42. Imagettftext ($im, 0,50, Rand (20,30), $mycolor, $font, $arrstr [0]);
  43. Imagettftext ($im, 0,50, Rand (20,30), $mycolor, $font, $arrstr [1]);
  44. Imagettftext ($im, 0,50, Rand (20,30), $mycolor, $font, $arrstr [2]);
  45. Imagettftext ($im, Max, Rand (0,50), Max, Rand (20,30), $mycolor, $font, $arrstr [3]);
  46. $font 2=imagecolorallocate ($im, 41,163,238);
  47. Imagerectangle ($im, 0,0,1,1, $font 2);
  48. Imagepng ($im);
  49. Imagedestroy ($im);
  50. }
  51. }
Copy Code
  • Related Article

    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.