PHP draws the verification code for the homepage image of website logon,

Source: Internet
Author: User

PHP draws the verification code for the homepage image of website logon,

Verification codes are available on almost all website login pages. Verification codes are a security protection mechanism. Manual verification is required during registration, it is used to prevent a large number of registered user accounts from occupying the server memory, thus paralyzing the server.

The implementation of the image verification code is very simple. First, a fixed number of characters are randomly extracted from the specified character set, and painted on the canvas in an irregular way. Then, some interference points and interference elements are added as appropriate, and the image is output, A brand new verification code is complete.

The generated verification code is displayed first:

 

Click to refresh:

 

If you are very satisfied with the Implementation Effect, please continue to look at it.

The front-end code is as follows:

<! DOCTYPE html> 

The php script file verification code is as follows:

<? Phpsession_start (); // enable the session record verification code data vCode (4, 15); // set the number of characters in the verification code and the Image Base Width // Number of vCode characters, font size, function vCode ($ num = 4, $ size = 20, $ width = 0, $ height = 0 ){! $ Width & $ width = $ num * $ size x 4/5 + 15 ;! $ Height & $ height = $ size + 10; // set the verification code character set to $ str = "23456789 abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW"; // Save the obtained Verification code $ code = ''; // randomly select the character for ($ I = 0; $ I <$ num; $ I ++) {$ code. = $ str [mt_rand (0, strlen ($ str)-1)];} // create a verification code canvas $ im = imagecreatetruecolor ($ width, $ height ); // background color $ back_color = imagecolorallocate ($ im, mt_rand (0,100), mt_rand (0,100), mt_rand (0,100); // text color $ text_color = imagecolorallocate ($ im, mt_ra Nd (100,255), mt_rand (100,255), mt_rand (100,255); imagefilledrectangle ($ im, 0, 0, $ width, $ height, $ back_color ); // draw interference lines for ($ I = 0; $ I <5; $ I ++) {$ font_color = imagecolorallocate ($ im, mt_rand (0,255 ), mt_rand (0,255), mt_rand (0,255); imagearc ($ im, mt_rand (-$ width, $ width), mt_rand (-$ height, $ height), mt_rand (30, $ width * 2), mt_rand (20, $ height * 2), mt_rand (0,360), mt_rand (0,360), $ font_colo R) ;}// draw interference points for ($ I = 0; $ I <50; $ I ++) {$ font_color = imagecolorallocate ($ im, mt_rand (0,255 ), mt_rand (0,255), mt_rand (0,255); imagesetpixel ($ im, mt_rand (0, $ width), mt_rand (0, $ height), $ font_color );} // random rotation angle array $ array = array (5, 4, 3, 2, 1, 0,-1,-2,-3,-4,-5 ); // output verification code // imagefttext (image, size, angle, x, y, color, fontfile, text) @ imagefttext ($ im, $ size, array_rand ($ array ), 12, $ size + 6, $ text_color, 'c :\ WINDOWS \ Fonts \ simsun. ttc ', $ code); $ _ SESSION ["VerifyCode"] = $ code; // no-cache will access the server upon each request // max-age will access the server upon another 1 s request, and must-revalidate will access the server upon the first request, the server will not be accessed later // header ("Cache-Control: max-age = 1, s-maxage = 1, no-cache, must-revalidate "); header ("Cache-Control: no-cache"); header ("Content-type: image/png; charset = gb2312 "); // convert the image to png format imagepng ($ im); imagedestroy ($ im);}?>

Well, I will introduce you so much about the php image Verification provided by the small Editor. I hope it will help you!

Articles you may be interested in:
  • Php image Verification Code
  • Php5 image Verification Code
  • Php generates random Verification Code Image Code
  • PHP programming fastest: php image verification code and thumbnails
  • PHP image Verification Code production implementation sharing (full)
  • How to Use php to generate distorted and rotated Verification Code Images
  • PHP generates a GIF image Verification Code
  • A pretty PHP image Verification Code instance
  • PHP generates image verification codes and click to switch instances
  • Php generates an image verification code-five verification codes are attached

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.