Php verification code only displays the canvas in linux, but does not display the ultimate solution of the verification code _ PHP Tutorial

Source: Internet
Author: User
In linux, the php verification code only displays the canvas. the ultimate solution is not to display the verification code. After passing the test, first release my code [php]? Phpsession_start (); ** remove boom to UTF-8 * vCode (m, n, x, y). The size of m digits is n-side width x-side height y * blog. qita. in * after testing, I first release my code


[Php] Session_start ();
/** Remove boom as UTF-8.
* The value of vCode (m, n, x, y) m is n-side width x-side height y.
* Http://blog.qita.in
* Record the session $ code by yourself
*/

VCode (4, 12); // 4 digits, the display size is 15

Function vCode ($ num = 4, $ size = 20, $ width = 0, $ height = 0 ){
! $ Width & amp; $ width = $ num * $ size * 4/5 + 5;
! $ Height & $ height = $ size + 10;
// Remove 0 1 O l and so on
$ Str= "23456789 abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW ";
$ Code = '';
For ($ I = 0; $ I <$ num; $ I ++ ){
$ Code. = $ str [mt_rand (0, strlen ($ str)-1)];
}
// Draw an image
$ Im = imagecreatetruecolor ($ width, $ height );
// Define the color to be used
$ Back_color = imagecolorallocate ($ im, 235,236,237 );
$ Boer_color = imagecolorallocate ($ im, 118,151,199 );
$ Text_color = imagecolorallocate ($ im, mt_rand (0,200), mt_rand (0,120), mt_rand (0,120 ));
// Draw the background
Imagefilledrectangle ($ im, 0, 0, $ width, $ height, $ back_color );
// Draw a border
Imagerectangle ($ im, 0, 0, $ width-1, $ height-1, $ boer_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_color );
}
// 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 );
}
// Drawing verification code http://www.ruoshuiyx.com reproduced please retain the source Thank you, will not affect your code execution speed if not please information if water impression network webmaster
// @ Imagefttext ($ im, $ size, 0, 5, $ size + 3, $ text_color, 'C: \ WINDOWS \ Fonts \ simsun. ttc ', $ code );
// The above is the trial in windows and the trial in LINUX, the corresponding font needs to be uploaded
@ Imagefttext ($ im, $ size, 0, 5, $ size + 3, $ text_color, '../msyh. ttf', $ code );
$ _ SESSION ["VerifyCode"] = strtolower ($ code); // converts it to lowercase.
Header ("Cache-Control: max-age = 1, s-maxage = 1, no-cache, must-revalidate ");
Header ("Content-type: image/png; charsets = utf-8 ");
Imagepng ($ im );
Imagedestroy ($ im );
}

?>

Session_start ();
/** Remove boom as UTF-8.
* The value of vCode (m, n, x, y) m is n-side width x-side height y.
* Http://blog.qita.in
* Record the session $ code by yourself
*/

VCode (4, 12); // 4 digits, the display size is 15

Function vCode ($ num = 4, $ size = 20, $ width = 0, $ height = 0 ){
! $ Width & amp; $ width = $ num * $ size * 4/5 + 5;
! $ Height & $ height = $ size + 10;
// Remove 0 1 O l and so on
$ Str= "23456789 abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW ";
$ Code = '';
For ($ I = 0; $ I <$ num; $ I ++ ){
$ Code. = $ str [mt_rand (0, strlen ($ str)-1)];
}
// Draw an image
$ Im = imagecreatetruecolor ($ width, $ height );
// Define the color to be used
$ Back_color = imagecolorallocate ($ im, 235,236,237 );
$ Boer_color = imagecolorallocate ($ im, 118,151,199 );
$ Text_color = imagecolorallocate ($ im, mt_rand (0,200), mt_rand (0,120), mt_rand (0,120 ));
// Draw the background
Imagefilledrectangle ($ im, 0, 0, $ width, $ height, $ back_color );
// Draw a border
Imagerectangle ($ im, 0, 0, $ width-1, $ height-1, $ boer_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_color );
}
// 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 );
}
// Drawing verification code http://www.ruoshuiyx.com reproduced please retain the source Thank you, will not affect your code execution speed if not please information if water impression network webmaster
// @ Imagefttext ($ im, $ size, 0, 5, $ size + 3, $ text_color, 'C: \ WINDOWS \ Fonts \ simsun. ttc ', $ code );
// The above is the trial in windows and the trial in LINUX, the corresponding font needs to be uploaded
@ Imagefttext ($ im, $ size, 0, 5, $ size + 3, $ text_color, '../msyh. ttf', $ code );
$ _ SESSION ["VerifyCode"] = strtolower ($ code); // converts it to lowercase.
Header ("Cache-Control: max-age = 1, s-maxage = 1, no-cache, must-revalidate ");
Header ("Content-type: image/png; charsets = utf-8 ");
Imagepng ($ im );
Imagedestroy ($ im );
}

?>

After copying and downloading, note lines 41 and 43. if the server is windows, comment out lines 43 and keep lines 41. if the server is windows, replace lines 43.

In linux, note that the corresponding font should be placed in the parent directory. for example, I use. Other methods will not be shown in the end. Try it now

Why [php]? Php session_start ();/** remove boom as UTF-8 * vCode (m, n, x, y) m digit display size is n side width x side height y * http://blog.qita.in *...

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.