Home > Backend Development > PHP Tutorial > Example of PHP numerical verification code_PHP tutorial

Example of PHP numerical verification code_PHP tutorial

WBOY
Release: 2016-07-13 10:42:38
Original
852 people have browsed it

It is very convenient to implement verification code in php. The key point is to master the usage of php gd library and session.

Looking at the examples of PHP generating verification codes on the Internet, it is all done by combining the PHP gd library with the session and using PHP to generate random numbers.

PHP verification code can be divided into many types, including php picture verification code, php random verification code, and php Chinese verification code, etc. Different verification codes are used according to different application scenarios.

Here is a PHP digital verification code for your reference.


1. Digital verification code
  • Please enter the verification code: "width:80px">
  • "Verification"value="Submit verification code">
  • echo$authnum;?>>
  • echo$authnum;?>>
  • 2. authimg.php
    1. //Generate verification code image
    2. Header("Content-type:image/PNG");
    3. srand((double)microtime()*1000000);//Sow a seed to generate random numbers to facilitate the use of random number generation below
    4. session_start();//Save random numbers into session
    5. $_SESSION['authnum']="";
    6. $im=imagecreate(62,20);//Specify the image background size
    7. $black=ImageColorAllocate($im,0,0,0);// Set three colors
    8. $white=ImageColorAllocate($im,255,255,255);
    9. $gray=ImageColorAllocate($im,200,200,200);
    10. imagefill($im,0,0,$gray);//Adopt area Filling method, set (0,0)
    11. while(($authnum=rand()%100000)<10000);
    12. //Draw the four-digit integer verification code into the picture
    13. // www.jbxue.com
    14. $_SESSION['authnum']=$authnum;
    15. imagestring($im,5,10,3,$authnum,$black);
    16. //Use col color to draw the string s to the x, y coordinates of the image represented by image (the upper left corner of the image is 0,0).
    17. //If font is 1, 2, 3, 4 or 5, use the built-in font
    18. for($i=0;$i< 200;$i++)//Add interference pixels
    19. {
    20. $randcolor=ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255)) ;
    21. imagesetpixel($im,rand()%70,rand()%30,$randcolor);
    22. }
    23. ImagePNG($im);
    24. ImageDestroy($im);
    25. ?>

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/634161.htmlTechArticleIt is very convenient to implement verification code in php. The key point is to master the usage of php gd library and session. Looking at the examples of PHP generating verification codes on the Internet, all of them are the combination of PHP gd library and session, and...
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template