PHP Image Verification Code making (top) _php tutorial

Source: Internet
Author: User
Recently was learning PHP Getting started, and now just getting started, so many do not know, from the most basic learning, will not be on the Internet to check, and then put it in this magic weapon, just as today encountered immediately function rand (); Think of what to do with it, and finally think of the verification Code, digital Verification Code, letter verification Code, Chinese verification code, but I will not ah, how to search the Internet, look at other people's code, open do not understand, watching the video, listen to the teacher, will be encountered in the function, note the place to take notes, usually see the general Web page random verification code is surrounded by a certain box, it seems to be the background of the picture.
After watching, I knocked, although encountered a lot of problems, but I believe that as long as their down-to-earth, must learn. Now want to do a summary, I may write very messy, but I believe that one day will be realized.
1. Random number of generated numbers--"Create picture-" random number in the picture-"in the picture added interference value (point, line)-" Keep in session-"in the form form reference;
Random functions: rand (int min,int max); Original aim, I looked at many of the online generated random numbers of code, there are numbers and letters random number, Chinese random number (array), etc., can not be separated from rand ();
The code is as follows (some online copy, I hope you don't take offense AH
The first type:

$authnum = ";
$ychar = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
$list =explode (",", $ychar);//Split function
for ($i =0; $i <4; $i + +) {
$randnum =rand (0,35);
$authnum. = $list [$randnum];//output as an array

The second type:

Private Function Createcheckcode ()
{
for (i=0;i codenum;i++)
{
Number = rand (0,2);
Switch (number)
{
Case 0:rand_number = rand (48,57); break;//Digital
Case 1:rand_number = rand (65,90); break;//Capital Letter
Case 2:rand_number = rand (97,122); break;//lowercase Letter
}
$ASC = sprintf ("%c", Rand_number);
$ASC _number = ASC_NUMBER.ASC;
}
return asc_number;

}

The third type:
Srand (Microtime () *100000);//equivalent to a timer
$string = "abcdefghigklmnopqrstuvwxyz123456789";
for ($i =0; $i <4; $i + +)
{
$new _number.= $string [Rand (0,strlen ($string)-1)];//immediately produces an array
}

The fourth type:
for ($i =0; $i <4; $i + +)
{
$rand. =dechex (rand (1,15));//convert decimal to hexadecimal
}
GD Library: (IPI with a series of image processing functions, generating picture processing images)
Enable PHP in the GD library: php.ini configuration file, remove the "; Extension=php_gd2.dll" in ";";
Some of the GD library functions are introduced:
1.imagecreatetruecolor (int x_size,int y_size) New true Color image
2.imagecolorallocate (Resource Image,int red,int green,int blue) assigns a color to an image, with three primary colors
3.imagestring (resource,font,int x,int y,content,color) Drawing function
4.header ("content-type:image/jpeg") output function www.2cto.com
The header of PHP is defined as the action of the Head, which supports the 3 type in PHP5:
1,content-type:xxxx/yyyy
2,location:xxxx:yyyy/zzzz
3,status:nnn xxxxxx
XXXX/YYYY indicates the type of content file
such as: Image/gif
Image/jpeg
Image/png
Imagejpeg (), Imagegif (), Imagepang ()
5.iamgeline (Resource image,int x1,int y1,int x2,int y2,int color); Draw line function, (int x,int y) starting coordinates
6.imagesetpixel (Resource image,int x,int y,int color) Draw point function
7.imagettftext (Resource image,float size,float angle,int x,int y,int color,string fontfile,string text) with font write function
8.iconv ("gb2312", "Utf-8", "string"); The first thing to do is to convert the text into utf-8 format PHP code to insert the Chinese method.
Code please see PHP Verification Code production (below)

Excerpted from Ms. Yuan

http://www.bkjia.com/PHPjc/478238.html www.bkjia.com true http://www.bkjia.com/PHPjc/478238.html techarticle recently was learning PHP Getting started, and now just getting started, so many do not know, from the most basic learning, will not be on the Internet to check, and then put it in this magic weapon, as today met immediately ...

  • Related Article

    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.