PHP implementation is applicable to the custom verification code class, php verification code. PHP implementation applies to the custom verification code class. The php verification code example in this article shares the PHP verification code class and the verification code class implemented by the object for your reference, the specific content is as follows: PHP implementation applies to the custom verification code class, php verification code class
Examples in this article share the PHP verification code class and the verification code class implemented by using objects for your reference. the specific content is as follows:
<? Php/** To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */Class Image {private $ img; public $ width = 85; public $ height = 25; public $ code; public $ code_len = 4; public $ code_str = "Hangzhou "; public $ bg_color = '# DCDCDC'; public $ font_size = 16; public $ font = 'font. ttf'; public $ font_color = '#000000'; // Create a verification code hunger character to create public function create_code () {$ code = ''; for ($ I = 0; $ I <$ this-> code_len; $ I ++) {$ code. = $ this-> code_str [mt_rand (0, strlen ($ this-> code_str)-1)];} return $ this-> code = $ code ;} // output Image public function getImage () {$ w = $ this-> width; $ h = $ this-> height; $ bg_color = $ this-> bg_color; $ img = imagecreatetruecolor ($ w, $ h); $ bg_color = imagecolorallocate ($ img, hexdec (substr ($ bg_color, 1, 2), hexdec (substr ($ bg_color, 3, 2), hexdec (substr ($ bg_color, 5, 2); imagefill ($ img, 0, 0, $ bg_color); $ this-> img = $ img; $ this-> create_font (); $ this-> create_pix (); $ this-> show_code ();} // write the verification code public function create_font () {$ this-> create_code (); $ color = $ this-> font_color; $ font_color = imagecolorallocate ($ this-> img, hexdec (substr ($ color, 1, 2 )), hexdec (substr ($ color, 3, 2), hexdec (substr ($ color, 5, 2); $ x = $ this-> width/$ this-> code_len; for ($ I = 0; $ I <$ this-> code_len; $ I ++) {$ txt_color = imagecolorallocate ($ this-> img, mt_rand (0,100 ), mt_rand (0,150), mt_rand (0,200); imagettftext ($ this-> img, $ this-> font_size, mt_rand (-30, 30 ), $ x * $ I + mt_rand (3, 6), mt_rand ($ this-> height/1.2, $ this-> height), $ txt_color, $ this-> font, $ this-> code [$ I]); // imagestring ($ this-> img, $ this-> font_size, $ x * $ I + mt_rand (3, 6 ), mt_rand (0, $ this-> height/4), $ this-> code [$ I], $ font_color) ;}$ this-> font_color = $ font_color ;} // draw the interference line public 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 <4; $ j ++) {imagesetthickness ($ this-> img, mt_rand (1, 2 )); 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) ;}// get the verification code public function getCode () {return strtoupper ($ this-> code);} // output the verification code private function show_code () {header ("Content-type: image/png "); imagepng ($ this-> img); imagedestroy ($ this-> img );}}
:
Highlights: ASP. NET verification code Daquan PHP verification code Daquan java verification code Daquan
The above is all the content of the verification code class written using objects. I hope it will be helpful for you to learn about PHP programming.
Examples in this article share the PHP verification code class and the verification code class implemented by using objects for your reference. the specific content is as follows...