PHP generates 4-bit digital verification Code implementation codes, PHP generated 4-bit verification Code _php tutorial

Source: Internet
Author: User

PHP generates 4-bit digital verification Code implementation codes, PHP generated 4-bit verification code


It is very convenient to implement verification code in PHP, the key point is to master the use of PHP GD Library and session.

Throughout the online PHP generation Verification code example, is not all PHP GD library and session combination, and the use of PHP generated random number method to complete.

PHP Verification code, can be divided into many kinds, including PHP image Verification Code, PHP random Verification Code, as well as PHP Chinese Verification Code , according to different applications to use different verification code.

Here to share a PHP digital verification code, for everyone's reference.

4-bit Digital verification code

/**filename:authpage.php*/session_start (); Srand (Double) microtime () *1000000); $authnum =$_session[' Authnum ']; Verify that the user input is consistent with the verification code if (Isset ($_post[' authinput ')) {if (strcmp ($_post[' authinput '],$_session[' Authnum ']) (==0) echo " Verify success! "; else echo "Validation failed! "; }     Generate a new four-bit integer verification Code     //while (($authnum =rand ()%10000) <1000);?>  

authimg.php

<?php//Generate Verification code picture Header ("content-type:image/png"); Srand (Double) microtime () *1000000);//sow a seed that generates random numbers to facilitate the use of session_start () generated by the random number below   ;//Put a random number in the session $_session [' Authnum ']= '; $im =imagecreate (62,20);//Make picture background size   $black =imagecolorallocate ($im, 0,0,0);//Set Three colors $white =imagecolorallocate ($ im,255,255,255); $gray =imagecolorallocate ($im, 200,200,200);   Imagefill ($im, 0,0, $gray);//Use Region fill, set (0,0) while   (($authnum =rand ()%100000) <10000);//Draw four-bit integer verification code into the picture $_ session[' Authnum ']= $authnum; Imagestring ($im, 5,10,3, $authnum, $black); Use the 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). If the font is 1,2,3,4 or 5, use the built-in font for   ($i =0; $i <200; $i + +)//Add interference pixel {$randcolor =imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255)); Imagesetpixel ($im, Rand ()%70,rand ()%30, $randcolor); } imagepng ($im); Imagedestroy ($im);?>

The above is the implementation code of PHP 4-bit digital verification code, I hope that everyone's learning has helped, we can more proficient in the operation of PHP verification code.

http://www.bkjia.com/PHPjc/1074661.html www.bkjia.com true http://www.bkjia.com/PHPjc/1074661.html techarticle PHP to generate 4-bit digital verification Code implementation code, PHP generated 4-bit verification code in PHP to implement the verification code is still very convenient, the key point is to master the PHP GD Library and session usage. Throughout the online p ...

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