最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php实现的简单中文验证码功能的实例
时间:2017-01-05 编辑:简简单单 来源:一聚教程网
本文实例讲述了php实现的简单中文验证码功能。分享给大家供大家参考,具体如下:
img.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, 0, 0);
$color= imagecolorallocate($image, 255, 255, 255);
//imagestring($image, rand(1,6), rand(3,60), rand(3,15), $rand, $color);
for($i=0;$i<3;$i++) {
$color2= imagecolorallocate($image, rand(0,255), rand(0,255),rand(0,255));
imageline($image, rand(0,100), 0, 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, 0, 20, 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
运行效果图如下:
-
上一个: 详解Python模板引擎的注入问题
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24