Php image verification code-PHP source code

Source: Internet
Author: User
Ec (2); & nbsp; php Verification Code Program & nbsp; Verification Code phpphp image Verification Code & lt ;? Php * @ date & nbsp; 20080514 @ author & nbsp; & nbsp; hlua script ec (2); script

Php Verification Code ProgramVerification Code phpPhp image Verification Code

/*
@ Date 20080514
@ Author hluan

// Session_start ();
Class icode
{
Function _ construct (){
Header ('content-Type: image/png ');
}
Function _ destruct (){
Imagedestroy ($ png );
}

Function getcode ($ len, $ type ){
Switch ($ type ){
Case 1;
$ Str = "1234567890 ";
Break;
Case 2;
$ Str = "abcdefghijklmnopqrstuvwxyz ";
Break;
Case 0;
$ Str = "1234567890 abcdefghijklmnopqrstuvwxyz ";
Break;
}
$ Result = "";
$ Length = strlen ($ str)-1;
$ Num = 0;
For ($ I = 0; $ I <$ len; $ I ++ ){
$ Num = rand (0, $ length );
$ A = $ str [$ num];
$ Result = $ result. $;
}
/* Before using it, you shoshould use session_start ()*/
$ _ SESSION ['code'] = $ result; // Store in session.
// Echo "session:". $ _ SESSION ['icode'];
// Die ();
$ Png = imagecreate (60, 30 );
$ White = imagecolorallocate ($ png, 255,255,255); // background
$ Red = imagecolorallocate ($ png, 255, 0, 0 );
$ Blue = imagecolorallocate ($ png, 255 );
$ Brown = imagecolorallocate ($ png, 100,0, 0 );
$ Black = imagecolorallocate ($ png, 0, 0); // Identifying Code
Imagefill ($ png, 0, 0, $ white );
$ K = rand (0, 3 );
If (0 = $ k ){
For ($ n = 0; $ n <60; $ n ++ ){
$ Y = 15 * sin ($ n/30 * pi ());
Imagesetpixel ($ png, $ n, 15 + $ y, $ red );
}
} Else if (1 ==$ k ){
For ($ n = 0; $ n <60; $ n ++ ){
$ Y = 15 * cos ($ n/60 * pi ());
Imagesetpixel ($ png, $ n, 15 + $ y, $ red );
}
} Else if (2 = $ k ){
For ($ n = 0; $ n <60; $ n ++ ){
$ Y = 15 * sin ($ n/45 * pi ());
Imagesetpixel ($ png, $ n, 15 + $ y, $ brown );
}
} Else if (3 ==$ k ){
For ($ n = 0; $ n <60; $ n ++ ){
$ Y = 15 * cos ($ n/30 * pi ());
Imagesetpixel ($ png, $ n, 15 + $ y, $ brown );
}
}
For ($ k = 0; $ k <10; $ k ++ ){
$ I = rand (3,60); // width
$ J = rand (3, 15); // height
Imageline ($ png, $ I-3, $ J-3, $ I, $ j, $ black );
}
Imagestring ($ png, 5, 3, 5, $ result, $ blue );
$ Icode = imagepng ($ png );
Return $ icode;
}
}
/* Test code
$ Icode = new icode ();
$ Icp = $ icode-> getcode (6, 0 );
Echo $ icp;
*/

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.