I just wrote a PHP efficient verification code function.

Source: Internet
Author: User
I don't like a simple verification code, because it costs a lot of weeks, and even font files are available. I often find that some programs only have more than two megabytes, And the font accounts for at least 1.5 MB, alas! I don't know what that person thinks. It's just too creative.
I don't like it, so I wrote a simple and beautiful and efficient one myself.

// If you want to publish this article, please indicate the exit, no outgoing copyright notice, I do not like to see this kind of website. My work website does not indicate the person who is serving Seven {See7di # Gmail.com}

<? Php
$ Work = AddsLashes ($ _ REQUEST ["work"]);
Switch ($ work ){
Case "cod ":
_ Cod ();
Break;
Default:
_ Main ();
Break;
}
//------------------------------------------------*
Function _ main (){
Session_start ();
Echo "}
//------------------------------------------------*
Function _ cod (){
OB_start ();
OB_clean ();
For ($ I = 0; $ I <4; $ I ++) {// dechex converts the 10-in-hexadecimal notation to the 16-in-hexadecimal notation.
$ Num. = Dechex (Mt_Rand (1, 15 ));
}

Session_start (); $ _ SESSION ['cod '] = $ num;

$ Img = Imagecreatetruecolor (60, 20); // create a canvas
$ Bgc = Imagecolorallocate ($ img, 255,255,255); // create an image background color.
Imagefill ($ img, 0, 0, $ bgc );

For ($ I = 0; $ I <Mt_Rand (); $ I ++) {// Add random lines
$ Linc = Imagecolorallocate ($ img, 200,200, Mt_Rand (0,255 ));
Imageline ($ img, Mt_Rand (5, 55), Mt_Rand (5, 15), Mt_Rand (5, 55), Mt_Rand (5, 15), $ linc );
}

For ($ I = 0; $ I <2; $ I ++ ){
$ Col = Imagecolorallocate ($ img, Mt_Rand (100,150), Mt_Rand (0,200); // font color
Imagestring ($ img, 6, (10 + $ I * 9), (2 + $ I * 2), ($ num [$ I]. "-". $ num [($ I + 2)]), $ col); // write text
}

Header ('content-type: Image/png ');
Imagepng ($ img );
Die ();
}
?>

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.