PHP high-definition security verification code _ PHP Tutorial

Source: Internet
Author: User
PHP high-definition security verification code. Copy the code as follows :? Phppublicfunctioncaptcha () {$ font_dir $ _ SERVER [DOCUMENT_ROOT]. your_ttf_file.ttf; library $ img_w58; set the image width $ img_h20; The code is as follows:


Public function captcha (){
$ Font_dir = $ _ SERVER ["DOCUMENT_ROOT"]. "your_ttf_file.ttf"; // Library
$ Img_w = 58; // set the image width
$ Img_h = 20; // set the image height.
$ Font_size = 11; // font size
$ Angle_l =-10; // left angle
$ Angle_r = 10; // right angle
$ Code_str = "ABCDEFGHJKLMNPQRSTUVWXYZ36 ";
$ Word_len = 4; // Number of digits of the verification code
$ Padding = 5; // interval between two texts
$ Margin = 2; // left margin
$ Base_line = 15; // text baseline position
$ Base_line_offset = 2; // baseline offset
$ Pixel_num = 3; // the base number of vertices.
$ Pixel_color = 8; // only the total number of points in the $ pixel_color color is $ pixel_num * $ pixel_color
$ Noise_font_size = 1; // Miscellaneous font size
$ Session_key = "my. xoyo_captcha"; // custom session key name

Header ("Cache-Control: no-cache, must-revalidate ");
Header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT ");
Header ("Pragma: no-cache ");
Header ("Cache-control: private ");
Header ('content-Type: image/png ');

Session_start ();
$ Word = "";
$ Code_str_len = strlen ($ code_str)-1;
For ($ I = 0; $ I <$ word_len; $ I ++ ){
$ Word. = $ code_str [rand (0, $ code_str_len)];
}
$ _ SESSION [$ session_key] = strtolower ($ word );
$ Image = imagecreatetruecolor ($ img_w, $ img_h );
Imagefilledrectangle ($ image, 0, 0, $ img_w-1, $ img_h-1, imagecolorallocate ($ image, mt_rand (235,255), mt_rand (235,255 ), mt_rand (235,255 )));

// Draw the Miscellaneous
For ($ I = 0; $ I <$ pixel_color; $ I ++ ){
$ Noise_color = imagecolorallocate ($ image, mt_rand (150,225), mt_rand (150,225), mt_rand (150,225 ));
For ($ j = 0; $ j <$ pixel_num; $ j ++ ){
Imagestring ($ image, $ noise_font_size, mt_rand (-10, $ img_w), mt_rand (-10, $ img_h), $ code_str [mt_rand (0, $ code_str_len)], $ noise_color );
}
}

// Draw text
For ($ I = 0; $ I <$ word_len; ++ $ I ){
$ Color = imagecolorallocate ($ image, mt_rand (0,100), mt_rand (20,120), mt_rand (50,150 ));
Imagettftext ($ image, $ font_size, mt_rand ($ angle_l, $ angle_r), $ margin, mt_rand ($ base_line-$ base_line_offset, $ base_line + $ base_line_offset), $ color, $ font, mb_substr ($ word, $ I, 1, 'utf-8 '));
$ Margin + = (imagefontwidth ($ font_size) + $ padding );
}

Imagepng ($ image );
Imagedestroy ($ image );
Exit;
}

The http://www.bkjia.com/PHPjc/324532.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324532.htmlTechArticle code is as follows :? Php public function captcha () {$ font_dir = $ _ SERVER ["DOCUMENT_ROOT"]. "your_ttf_file.ttf"; // Library $ img_w = 58; // set the image width to $ img_h = 20 ;/...

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.