The concrete implementation method of PHP graphics verification Code _php tutorial

Source: Internet
Author: User
We are now in the site registration and other places often see you need to enter a verification code, it is the random numbers or symbols in the form of a picture in front of the user, and provide verification before using the relevant features. Today we will introduceThe specific implementation code is as follows:

 
 
  1. php
  2. Class rndnum{
  3. function rnd () {
  4. Srand (Double) microtime () *1000000);
  5. $ Rnd_number = Array (
  6. 1 = > ' 1 ',
  7. 2 = > ' 2 ',
  8. 3 = > ' 3 ',
  9. 4 = > ' 4 ',
  10. 5 = > ' 5 ',
  11. 6 = > ' 6 ',
  12. 7 = > ' 7 ',
  13. 8 = > ' 8 ',
  14. 9 = > ' 9 ',
  15. Ten = > ' A ',
  16. One = > ' B ',
  17. A = > ' C ',
  18. - = > ' d ',
  19. - = > ' E ',
  20. the = > ' F ',
  21. - = > ' G ',
  22. - = > ' h ',
  23. - = > ' i ',
  24. + = > ' J ',
  25. - = > ' K ',
  26. + = > ' l ',
  27. A = > ' m ',
  28. at = > ' n ',
  29. - = > ' O ',
  30. - = > ' P ',
  31. - = > ' Q ',
  32. - = > ' R ',
  33. - = > ' s ',
  34. in = > ' t ',
  35. - = > ' u ',
  36. to = > ' V ',
  37. + = > ' W ',
  38. - = > ' x ',
  39. the = > ' y ',
  40. * = > ' z ',
  41. $ = > ' 0 '
  42. );
  43. $ result = Array_rand ($rnd _number,6);
  44. $ J = Count ($result);
  45. For ($i=0; $i<$j; $i + +) {
  46. $ Re. = $rnd _number[$result [$i]];
  47. }
  48. //$ Re = $rnd _number[$result [1]]. $rnd _number[$result [2]]. $rnd _number[$result [3]]. $rnd _number[$result [4]]. $rnd _ number[$result [5]]. $rnd _number[$result [6]]. $rnd _number[$result [7]];
  49. Return Array_keys ($result);
  50. return $re;
  51. }
  52. }
  53. /* Usage
  54. $ Rndnum = New Rndnum ();
  55. $ Num = $rndnum- > Rnd ();
  56. Echo $num;
  57. */
  58. ?>

Generate a picture of PHP graphics verification Code, fill the random number into the inside:

 
 
  1. php
  2. Header ("Content-type:image/png");
  3. Require_once ("rndnum.php");
  4. $ Rndnum = New Rndnum ();
  5. $ Authnum = $rndnum- > Rnd ();
  6. Session_Start ();
  7. $_session["Extrra_code"]= $authnum;
  8. $ im = imagecreate (72,20);
  9. $ Black = imagecolorallocate ($im, 0,0,0);
  10. $ White = imagecolorallocate ($im, 255,255,255);
  11. $ Gray = imagecolorallocate ($im, 200,200,200);
  12. Imagefill ($im, 0,0, $gray);
  13. Imagestring ($im, 5,10,3, $authnum, $black);
  14. For ($i=0; $i<$i + + )//Add interfering pixels
  15. {
  16. $ Randcolor = imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
  17. Imagesetpixel ($im, Rand ()%70, Rand ()%30, $randcolor);
  18. }
  19. Imagepng ($im);
  20. Imagedestroy ($im);
  21. ?>

The above is the implementation of all PHP graphics verification Code, I hope to help you.


http://www.bkjia.com/PHPjc/446423.html www.bkjia.com true http://www.bkjia.com/PHPjc/446423.html techarticle we are now in the site registration and other places often meet to require you to enter a verification code, it is to be random numbers or symbols in the form of a picture in front of the user, and provide verification before ...

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