介绍
这期内容当中小编将会给大家带来有关利用PHP怎么编写一个验证码类,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
具体内容如下
& lt; PHP ? ,/*, ,*用change 却;能够license 头,,choose license Headers 拷贝Project 属性。 ,*用change 却;能够template 文件,,choose Tools |模板 *大敌;以及open 从而template 拷贝,编辑器。 ,*/{Class 图像 ,, ,private img美元;=,public width 美元;85;=,public height 美元;25; 美元,public 代码; ,public code_len 美元;=,4;=,public code_str 美元;“329832983 dsdskdslkqwewq2lkfdsfsdjfdsfdsjwlkfj93290kfdskjfdsoidslk";=,public bg_color 美元;& # 39;# DCDCDC& # 39;;=,public font_size 美元;16;=,public font 美元;& # 39;font.ttf& # 39;;=,public font_color 美元;& # 39;# 000000 & # 39;; ,, ,//创建验证码饿字符创 ,public function  create_code () { 时间=美元才能code & # 39; & # 39;; 为(,,,i=0美元;i<美元;$ this→code_len;美元我+ +,){ ,,code 美元。=,$ this→code_str [mt_rand (0,, strlen ($ this→code_str) 1)]; ,} return 才能;这→美元code =,美元代码; ,} ,, ,//输出图像 ,public function  getImage () {=美元才能w $ this→宽度;=美元才能h $ this→高度;=美元才能bg_color $ this→bg_color; 时间=美元才能img imagecreatetruecolor (w美元,,h); 时间=美元才能bg_color imagecolorallocate (img美元,, 函数,substr (bg_color美元,,1,2)),,函数(substr (bg_color美元,,3,2)),,函数(substr (bg_color美元,,5,2))); ,imagefill (img美元,,0,0,,bg_color美元); 这个美元才能→img =, img美元; 这个美元才能→create_font (); 这个美元才能→create_pix (); ,$ this→show_code (); ,} , , ,//写入验证码 ,public function  create_font () { 这个美元才能→create_code ();=美元才能color $ this→font_color;=美元才能font_color imagecolorallocate ($ this→img,函数(substr(颜色美元,1,2)),,函数(substr(美元的颜色,,3,2)),,函数(substr(颜色美元,5,2)));=美元才能x $ this→宽/$ this→code_len; 为(,,,i=0美元;i<美元;$ this→code_len;美元我+ +,){ txt_color 美元,,,=,imagecolorallocate ($ this→img, mt_rand (0100), 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→高度/1.2,$ this→高度),,txt_color美元,美元这→font ,, $ this→代码[$ i]),, ,,//imagestring ($ this→img, $ this→font_size,, $ x * $ i + mt_rand (3, 6), mt_rand (0,, $ this→高度/4),,,这个→美元代码($ i),, font_color美元); ,,} 这个美元才能→font_color =, font_color美元; ,} ,, ,//画干扰线 ,public function  create_pix () { 美元$ pix_color=才能,这→font_color; ,,(我=0;i<美元;100美元我+ +){ ,,imagesetpixel ($ this→img, mt_rand (0,, $ this→宽度),mt_rand (0,, $ this→高度),,pix_color美元); ,,} ,,(j=0; j<美元;4 $ j + +) { ,,imagesetthickness ($ this→img, mt_rand (1, 2)); ,,imageline ($ this→img, mt_rand (0,, $ this→宽度),,mt_rand (0,, $ this→高度),,mt_rand (0,, $ this→宽度),,mt_rand (0,, $ this→高度),,pix_color美元); ,,} ,} ,, ,//得到验证码 ,public function  getCode () { return 才能strtoupper ($ this→代码); ,} , , ,//输出验证码 ,private function  show_code () { 头才能(“内容类型:图像/png"); imagepng才能($ this→img); imagedestroy才能($ this→img); ,} }
上述就是小编为大家分享的利用PHP怎么编写一个验证码类了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。