Image Verification code generation application instance _ PHP Tutorial

Source: Internet
Author: User
Image Verification code generation application instance. A simple php graphic verification code generation program. The example shows you how to use this verification program. if you need it, refer to it. The code is as follows: Copy the code? Php Tutorial session _ a simple php graphic verification code generation program. The example shows you how to use this verification program. if you need this verification program, refer to it.
The code is as follows:

Session_start (); // enable session
If (isset ($ _ POST ['check'])
{
If ($ _ POST ['check'])
{
If ($ _ POST ['check'] ==_ _ SESSION ['Check _ pic '])
{
Echo "the verification code is correct". $ _ SESSION ['Check _ pic '];
}
Else
{
Echo "verification code error". $ _ SESSION ['Check _ pic '];
}
}
}
?>

Index. php verification code generation program

The code is as follows:

Session_start ();


For ($ I = 0; $ I <4; $ I ++) // Four-digit verification code
{@ $ Rand. = dechex (rand (); // A random number, and then convert it to hexadecimal notation. note "."
}
$ _ SESSION ['Check _ pic '] = $ rand;
$ Im = imagecreatetruecolor (); // create an image
$ Bg = imagecolorallocate ($ im, 0); // set the color
$ Wh = imagecolorallocate ($ im, 255,255,255 );

Imagestring ($ im, 5, 15, 8, $ rand, $ wh); // font, 1-6

Header ("Content-type: image/jpeg"); // output image
Imagejpeg ($ im );
?>


Bytes. The code is as follows? Php Tutorial session _...

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.