A method of realizing simple verification code function using PHP drawing function _php Example

Source: Internet
Author: User
Tags rand

index.php

<?php
//=================================== "Use the drawing technique to draw the verification code

//1. Randomly generates 4 random numbers
$checkCode =" ";
For ($i =0 $i <4; $i + +) {
$checkCode. =dechex (1);//Decheck () decimal to 16, which is the number to display on the verification Code
}

//2. Save in column
session_start ();
$_session[' Checkcode ']= $checkCode;

3. Create canvas
$image 1=imagecreatetruecolor;

Manufacturing disturbances, creating 20 arcs for
($j =0 $j <30; $j + +) {
Imagearc ($image 1, rand (0), rand (0), rand (0, MB), rand (0, Rand (0, 360), rand (0, 360), Imagecolorallocate ($image 1, rand (0), rand (0, 255), rand (0, 255));

3. Create the font color, paste the word up
$white =imagecolorallocate ($image 1, 255, 255, 255);
Imagestring ($image 1, rand (2, 5), Rand (5), Rand (2,), $checkCode, $white);

5. Output image or Save
header ("Content-type:image/png");
Imagepng ($image 1);

6. Release of resources
Imagedestroy ($image 1);

login.php

Please enter the code: 

The above is a small series for everyone to bring the use of PHP drawing functions to achieve simple verification code function of the whole content, I hope that we support cloud-Habitat Community ~

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.