Use dynamic web skills PHP native verification code picture source code

Source: Internet
Author: User
Tags natural string
Use dynamic web skills PHP native verification code picture source code // random native string // verification code picture width // verification code picture height

File a. php

// CheckNum. php
Session_start ();
Function random ($ len)
{
$ Srcstr = \ "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 \";
Mt_srand ();
$ Strs = \"\";
For ($ I = 0; $ I <$ len; $ I ){
$ Strs. = $ srcstr [mt_rand (0, 35)];
}
Return strtoupper ($ strs );
}
$ Str = random (4); // random natural string
$ Width = 50; // the image width of the verification code
$ Height = 25; // height of the verification code Image
@ Header (\ "Content-Type: image/png \");
$ _ SESSION [\ "code \"] = $ str;
// Echo $ str;
$ Im = imagecreate ($ width, $ height );
// Back the landscape
$ Back = imagecolorallocate ($ im, 0xFF, 0xFF, 0xFF );
// Mixed color
$ Pix = imagecolorallocate ($ im, 187,230,247 );
// Font color
$ Font = imagecolorallocate ($ im, 41,163,238 );
// Draw the point of obfuscation
Mt_srand ();
For ($ I = 0; I I <1000; $ I)
{
Imagesetpixel ($ im, mt_rand (0, $ width), mt_rand (0, $ height), $ pix );
}
Imagestring ($ im, 5, 7, 5, $ str, $ font );
Imagerectangle ($ im, 0, 0, $ width-1, $ height-1, $ font );
Imagepng ($ im );
Imagedestroy ($ im );
$ _ SESSION [\ "code \"] = $ str;
?>

File B. php

Session_start ();
Echo \ "\"; // natural image
Echo $ _ SESSION [\ "code \"]; // natural verification code value
?>

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.