php实现的简单中文验证码功能示例

前端之家收集整理的这篇文章主要介绍了php实现的简单中文验证码功能示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了PHP实现的简单中文验证码功能分享给大家供大家参考,具体如下:

img.PHP

PHP;"> PHP session_start(); /*for($i=0;$i<4;$i++) { $rand .= dechex(rand(1,15)); } $_SESSION[check_pic] = $rand; */ $image = imagecreatetruecolor(100,30); $bg = imagecolorallocate($image,0); $color = imagecolorallocate($image,255,255); //imagestring($image,rand(1,6),rand(3,60),15),$rand,$color); for($i=0;$i<3;$i++) { $color2 = imagecolorallocate($image,rand(0,255),255)); imageline($image,100),100,30,$color2); } //rand() ---->0-max 不大于100 for($i=0;$i<200;$i++) { imagesetpixel($image,rand()%100,rand()%30,$color2); } //$str = iconv("gbk","utf-8","中"); $str = "中国"; $_SESSION[check_pic] = $str; //解决中文,页面本身为utf-8 $str = mb_convert_encoding($str,"html-entities","utf-8" ); //2:字体大小 3:倾斜角度 x,y 坐标 imagettftext($image,12,20,$color,'MSYH.TTF',$str); //输出图片 header("Content-type: image/jpeg;charset=utf-8"); imagejpeg($image); /*修改eclipse的配置,可以使得eclipse的新建项目的默认编码直接为UTF-8 在菜单栏的 Window->Preferences->General->Workspace->Text file encoding 将其改为UFT-8即可。*/ ?>

sub.PHP

PHP;">
PHP">

运行效果图如下:

更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》、《》及《PHP常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

原文链接:https://www.f2er.com/php/18158.html

猜你在找的PHP相关文章