PHP generates cool four character verification code, PHP generates cool verification Code _php tutorial

Source: Internet
Author: User
Tags learn php learn php programming sprintf

PHP generates cool four character verification code, PHP generates cool verification code


The example of this article for everyone to share the code of PHP generated verification codes, for your reference, the specific content as follows

<?php$im=imagecreate (200,100);//Generate Canvas Imagecolorallocate ($im, 0,0,0);//background-color $white=imagecolorallocate ($im, Rand ( 0,255), Rand (0,255), Rand (0,255));//Generate Random color for ($i =0; $i <9; $i + +) {Imageline ($im, Rand (0,200), Rand (0,100), Rand ( 0,200), Rand (0,100), $white);//Generate Interference line elements}for ($i =0; $i <150; $i + +) {Imagesetpixel ($im, Rand (0,200), Rand (0,100), $ white);//Generate a disturbance point element}for ($i =0, $str = "; $i <4; $i + +)//To get four characters {switch (rand (1,3)) {case  ' 1 ':  $ch =rand (0,9);  break;   Case ' 2 ':  $ch =sprintf ('%c ', rand (97,122));  break;  Case ' 3 ':  $ch =sprintf ('%c ', rand (65,90));  Break }  $str. = $ch;} Imagettftext ($im, 32,rand (0,15), 55,70, $white, ' C.TTC ', $str);//output string header on canvas ("Content-type:image/jpeg"); Imagejpeg ($im); Imagedestroy ($im);? >

The above is the whole content of this article, I hope that you learn PHP programming help.

http://www.bkjia.com/PHPjc/1122891.html www.bkjia.com true http://www.bkjia.com/PHPjc/1122891.html techarticle PHP generated cool four character verification code, PHP generated cool code in this example for everyone to share PHP code to generate verification codes for your reference, specific content as follows Php$im=imagec ...

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