A verification code written by PHP

Source: Internet
Author: User
  1. Session_Start ();
  2. $image = Imagecreatetruecolor (58,22);
  3. $color _background = imagecolorallocate ($image, 255,255,255);
  4. Imagefill ($image, 0,0, $color _background);
  5. $key = Array (
  6. ' 0′, ' 1′, ' 2′, ' 3′, ' 4′, ' 5′, ' 6′, ' 7′, ' 8′, ' 9′,
  7. ' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' h ', ' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' o ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' u ', ' V ', ' w ', ' x ', ' y ', ' z ',
  8. ' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ');
  9. $string = null;
  10. $char _x = 6;
  11. $char _y = 0;
  12. for ($i =0; $i <4; $i + +)
  13. {
  14. $char _y = Mt_rand (0,5);
  15. $char = $key [Mt_rand (0,61)];
  16. $string. = $char;
  17. $color _char = imagecolorallocate ($image, Mt_rand (0,230), Mt_rand (0,230), Mt_rand (0,230));
  18. Imagechar ($image, 5, $char _x, $char _y, $char, $color _char);
  19. $char _x = $char _x + mt_rand (8,15);
  20. }
  21. $line _x1 = 0;
  22. $line _y1 = 0;
  23. $line _x2 = 0;
  24. $line _y2 = 0;
  25. for ($i =0; $i
  26. {
  27. $line _x1 = Mt_rand (0,58);
  28. $line _y1 = Mt_rand (0,22);
  29. $line _x2 = Mt_rand (0,58);
  30. $line _y2 = Mt_rand (0,22);
  31. $line _x1 = $line _x1;
  32. $line _y1 = $line _y1;
  33. $line _x2 = $line _x1 + mt_rand (1,8);
  34. $line _y2 = $line _y1 + mt_rand (1,8);
  35. $color _line = imagecolorallocate ($image, Mt_rand (0,230), Mt_rand (0,230), Mt_rand (0,230));
  36. Imageline ($image, $line _x1, $line _y1, $line _x2, $line _y2, $color _line);
  37. }
  38. $_session[' seccode '] = $string;
  39. @header ("Expires: -1″);
  40. @header ("Cache-control:no-store, Private, post-check=0, Pre-check=0, Max-age=0″, FALSE);
  41. @header ("Pragma:no-cache");
  42. Header (' Content-type:image/jpeg ');
  43. Imagepng ($image);
  44. Imagedestroy ($image);
  45. ?>
Copy Code
  • 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.