PHP Verification code making ideas and implementation methods, PHP verification code making Ideas _php tutorial

Source: Internet
Author: User

How to make PHP verification code and how to make PHP verification code


First, the production of ideas

Because registration code is often used to prevent malicious machine registration, here I publish a PNG image verification code basic image, simple thinking Analysis:

1. Produce a picture of PNG
2. Set the background color for the picture
3. Set font color and style
4. Generate a 4-digit random verification code
5. Adjust the rotation angle and position of each character produced to the PNG image.
6, add noise and interference line to prevent the registration machine analysis of the original image to malicious registration
7. Output image
8. Release the memory of the image

Second, the realization method

authcode.php file

<?php session_start ();    Header (' content-type:image/png ');    Create Picture $im = Imagecreate ($x =130, $y = 45); $BG = Imagecolorallocate ($im, Rand (50,200), Rand (0,155), Rand (0,155));  The first call to Imagecolorallocate () fills the color palette-based image with the background color $fontColor = imagecolorallocate ($im, 255, 255, 255);          Font Color $fontstyle = ' Rock.ttf ';         Font style, this can be found from the C:\windows\Fonts\ folder, I put it in the same directory as the authcode.php file, here can replace the other font style//generate random characters for ($i = 0; $i < 4; $i + +) {        $randAsciiNumArray = Array (rand (48,57), Rand (65,90));        $randAsciiNum = $randAsciiNumArray [Rand (0, 1)];        $RANDSTR = Chr ($randAsciiNum);        Imagettftext ($im, 30,rand (0,20)-rand (0,25), 5+ $i *30,rand (30,35), $fontColor, $fontstyle, $RANDSTR);     $authcode. = $RANDSTR; } $_session[' Authcode ' = $randFourStr;//The user and user entered the verification code to do the comparison//interference line for ($i =0; $i <8; $i + +) {$lineColor =        Imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255)); Imageline ($im,Rand (0, $x), 0,rand (0, $x), $y, $lineColor);    }//Interference point for ($i =0; $i <250; $i + +) {Imagesetpixel ($im, rand (0, $x), rand (0, $y), $fontColor);    } imagepng ($im);        Imagedestroy ($im); ?>

:

The above is the PHP verification code making ideas and implementation methods, I hope that everyone's learning has helped.

http://www.bkjia.com/PHPjc/1071232.html www.bkjia.com true http://www.bkjia.com/PHPjc/1071232.html techarticle PHP Verification Code making ideas and implementation methods, PHP verification code production ideas first, production ideas because of the registration of the time will often use the registration code to prevent malicious machine registration, here I published a ...

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