Implementation code for parsing dedeCMS verification code

Source: Internet
Author: User
Tags imagejpeg
This article provides a detailed analysis of the dedeCMS verification code. For more information, see the following:

The code is as follows:


$ Rndstring = '';
For ($ I = 0; $ I <4; $ I ++) $ rndstring. = chr (mt_rand (65,90 ));
// If GD is supported, draw
If (function_exists ("imagecreate "))
{
// In some cases in Firefox, there will be multiple requests, and refreshing the page within 5 seconds will not change the session
$ Ntime = time ();
If (empty ($ _ SESSION ['DD _ ckstr_last ']) | empty ($ _ SESSION ['DD _ ckstr']) | ($ ntime-$ _ SESSION ['DD _ ckstr_last ']> 5 ))
{
$ _ SESSION ['DD _ ckstr'] = strtolower ($ rndstring );
$ _ SESSION ['DD _ ckstr_last '] = $ ntime;
}
$ Rndstring = $ _ SESSION ['DD _ ckstr'];
$ Rndcodelen = strlen ($ rndstring );
// Create an image and set the background color
$ Im = imagecreate (50, 20 );
ImageColorAllocate ($ im, 255,255,255 );
// Background line
$ LineColor1 = ImageColorAllocate ($ im, 240,220,180 );
$ LineColor2 = ImageColorAllocate ($ im, 250,250,170 );
For ($ j = 3; $ j <= 16; $ j = $ j + 3)
{
Imageline ($ im, 2, $ j, 48, $ j, $ lineColor1 );
}
For ($ j = 2; $ j <52; $ j = $ j + (mt_rand (3, 6 )))
{
Imageline ($ im, $ j, 2, $ J-6, 18, $ lineColor2 );
}
// Draw a border
$ Bordercolor = ImageColorAllocate ($ im, 0x99,0x99,0x99 );
Imagerectangle ($ im, 0, 0, 49, 19, $ bordercolor );
// Output text
$ FontColor = ImageColorAllocate ($ im, 48, 61, 50 );
For ($ I = 0; $ I <$ rndcodelen; $ I ++)
{
$ Bc = mt_rand (0, 1 );
$ Rndstring [$ I] = strtoupper ($ rndstring [$ I]);
Imagestring ($ im, 5, $ I * 10 + 6, mt_rand (2, 4), $ rndstring [$ I], $ fontColor );
}
Header ("Pragma: no-cache/r/n ");
Header ("Cache-Control: no-cache/r/n ");
Header ("Expires: 0/r/n ");
// Output a specific image format with a priority of gif-> jpg-> png
If (function_exists ("imagejpeg "))
{
Header ("content-type: image/jpeg/r/n ");
Imagejpeg ($ im );
}
Else
{
Header ("content-type: image/png/r/n ");
Imagepng ($ im );
}
ImageDestroy ($ im );
Exit ();
}
Else
{
// GD is not supported. only the English letter ABCD is output.
$ _ SESSION ['DD _ ckstr'] = "abcd ";
$ _ SESSION ['DD _ ckstr_last '] = '';
Header ("content-type: image/jpeg/r/n ");
Header ("Pragma: no-cache/r/n ");
Header ("Cache-Control: no-cache/r/n ");
Header ("Expires: 0/r/n ");
$ Fp = fopen ("data/vdcode.jpg", "r ");
Echo fread ($ fp, filesize ("data/vdcode.jpg "));
Fclose ($ fp );
Exit ();
}
?>

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.