Php verification class-PHP source code

Source: Internet
Author: User
Php verification class

[PHP] code
 Font = "font ". DIRECTORY_SEPARATOR. "arial. ttf ";}/** verification code generation function */private function create_code () {$ code =" "; for ($ I = 0; $ I <$ this-> code_len; $ I ++) {$ code. = $ this-> code_str [mt_rand (0, strlen ($ this-> code_str)-1)] ;}$ this-> code = $ code ;} /** get verification code */public function getcode () {return strtoupper ($ this-> code);}/** create image handle */public function getimg () {$ w = $ this-> width; $ h = $ this-> height; $ img = imagecr Eatetruecolor ($ w, $ h); $ bg_color = imagecolorallocate ($ img, hexdec (substr ($ bg_color, 1, 2), hexdec (substr ($ img, 3, 2 )), hexdec (substr ($ img, 5, 2); imagefill ($ img, $ bg_color); $ this-> img = $ img; $ this-> create_font (); $ this-> create_pix (); $ this-> show_code ();}/** create font */public function create_font () {$ this-> create_code (); $ color = $ this-> font_color; $ font_color = imagecolorallocate ($ this-> img, hexdec (su Bstr ($ color,), hexdec (substr ($ color,), hexdec (substr ($ color ))); $ x = $ this-> width/$ this-> code_len; for ($ I = 0; $ I <$ this-> code_len; $ I ++) {imagettftext ($ this-> img, $ this-> font_size, mt_rand (-30, 30), $ x * $ I + mt_rand (3, 6 ), mt_rand ($ this-& gt; height/1.2, $ this-& gt; height-5), $ font_color, $ this-& gt; font, $ this-& gt; code [$ I]);} $ this-> font_color = $ font_color;}/** writer interference */private function create_pix () {$ Pix_color = $ this-> font_color; for ($ I = 0; $ I <100; $ I ++) {imagesetpixel ($ this-> img, mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), $ pix_color);} for ($ j = 0; $ j <2; $ j ++) {imagesetthickness ($ this-> img, mt_rand (2, 4); imageline ($ this-> img, mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), $ pix_color );}} /** display code */private function show_code () {header ("Content -Type: image/png "); imagepng ($ this-> img); imagedestroy ($ this-> img); }}?>
[PHP] code
 Font = "font ". DIRECTORY_SEPARATOR. "arial. ttf ";}/** verification code generation function */private function create_code () {$ code =" "; for ($ I = 0; $ I <$ this-> code_len; $ I ++) {$ code. = $ this-> code_str [mt_rand (0, strlen ($ this-> code_str)-1)] ;}$ this-> code = $ code ;} /** get verification code */public function getcode () {return strtoupper ($ this-> code);}/** create image handle */public function getimg () {$ w = $ this-> width; $ h = $ this-> height; $ img = imagecr Eatetruecolor ($ w, $ h); $ bg_color = imagecolorallocate ($ img, hexdec (substr ($ bg_color, 1, 2), hexdec (substr ($ img, 3, 2 )), hexdec (substr ($ img, 5, 2); imagefill ($ img, $ bg_color); $ this-> img = $ img; $ this-> create_font (); $ this-> create_pix (); $ this-> show_code ();}/** create font */public function create_font () {$ this-> create_code (); $ color = $ this-> font_color; $ font_color = imagecolorallocate ($ this-> img, hexdec (su Bstr ($ color,), hexdec (substr ($ color,), hexdec (substr ($ color ))); $ x = $ this-> width/$ this-> code_len; for ($ I = 0; $ I <$ this-> code_len; $ I ++) {imagettftext ($ this-> img, $ this-> font_size, mt_rand (-30, 30), $ x * $ I + mt_rand (3, 6 ), mt_rand ($ this-& gt; height/1.2, $ this-& gt; height-5), $ font_color, $ this-& gt; font, $ this-& gt; code [$ I]);} $ this-> font_color = $ font_color;}/** writer interference */private function create_pix () {$ Pix_color = $ this-> font_color; for ($ I = 0; $ I <100; $ I ++) {imagesetpixel ($ this-> img, mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), $ pix_color);} for ($ j = 0; $ j <2; $ j ++) {imagesetthickness ($ this-> img, mt_rand (2, 4); imageline ($ this-> img, mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), mt_rand (0, $ this-> width), mt_rand (0, $ this-> height), $ pix_color );}} /** display code */private function show_code () {header ("Content -Type: image/png "); imagepng ($ this-> img); imagedestroy ($ this-> img); }}?>

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.