当前位置:首页 » 编程语言 » 中文验证码php

中文验证码php

发布时间: 2022-06-14 02:52:29

1. php验证码插入中文,为什么显示还是方格,我已经做了编码转换了。字体也有的

因为 ahronbd.ttf 这一个不是中文字库,你换一个中文字库就可以了。

2. 如何用PHP生成验证码

php生成验证码,php验证码,php怎样生成验证码?
工具/原料
这个验证码较实用,大家可以应用到项目中。
方法/步骤
1.
<?php
/*设置文件头为图片输出*/
Header("Content-type:image/JPEG");

/*调用生成验证码函数*/
$checkcode=make_rand(4);

/**
*生成验证码字符
*@paramint$length验证码字符长度
*@returnstring
*/
functionmake_rand($length="32"){
$str="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$result="";
for($i=0;$i<$length;$i++){
$num[$i]=rand(0,25);
$result.=$str[$num[$i]];
}
return$result;
}
2.
/*调用输出验证码图片函数*/
getAuthImage($checkcode,160,40);

/**
*生成验证码图片
*@paramstring$text验证码字符
*/
functiongetAuthImage($text,$w,$y){
/*设置图片的宽度和高度*/
$im_x=$w;
$im_y=$y;
/*创建图片*/
$im=imagecreatetruecolor($im_x,$im_y);
$text_c=ImageColorAllocate($im,mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
$tmpC0=mt_rand(100,255);
$tmpC1=mt_rand(100,255);
$tmpC2=mt_rand(100,255);
$buttum_c=ImageColorAllocate($im,$tmpC0,$tmpC1,$tmpC2);
imagefill($im,16,13,$buttum_c);
3.
/*字体文件*/
$font='t1.ttf';
for($i=0;$i<strlen($text);$i++)
{
$tmp=substr($text,$i,1);
$array=array(-1,1);
$p=array_rand($array);
$an=$array[$p]*mt_rand(1,10);//角度
$size=28;
imagettftext($im,$size,$an,15+$i*$size,35,$text_c,$font,$tmp);
}

/*将字符写入文件中*/
$distortion_im=imagecreatetruecolor($im_x,$im_y);
imagefill($distortion_im,16,13,$buttum_c);
for($i=0;$i<$im_x;$i++){
for($j=0;$j<$im_y;$j++){
$rgb=imagecolorat($im,$i,$j);
if((int)($i+20+sin($j/$im_y*2*M_PI)*10)<=imagesx($distortion_im)&&(int)($i+20+sin($j/$im_y*2*M_PI)*10)>=0){
imagesetpixel($distortion_im,(int)($i+10+sin($j/$im_y*2*M_PI-M_PI*0.1)*4),$j,$rgb);
}
}
}
4.
/*干扰元素点的数量*/
$count=160;
/*创建干扰元素点*/
for($i=0;$i<$count;$i++){
$randcolor=ImageColorallocate($distortion_im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($distortion_im,mt_rand()%$im_x,mt_rand()%$im_y,$randcolor);
}
/*创建干扰线条*/
$rand=mt_rand(5,30);
$rand1=mt_rand(15,25);
$rand2=mt_rand(5,10);
for($yy=$rand;$yy<=+$rand+2;$yy++){
for($px=-80;$px<=80;$px=$px+0.1)
{
$x=$px/$rand1;
if($x!=0)
{
$y=sin($x);
}
$py=$y*$rand2;
imagesetpixel($distortion_im,$px+80,$py+$yy,$text_c);
}
}
5.
/*以PNG格式将图像输出到浏览器*/
ImagePNG($distortion_im);

/*销毁图像*/
ImageDestroy($distortion_im);
ImageDestroy($im);

3. php中文验证码的思路是怎样的是在字符串里输入很多个中文让随机还是怎么样

$keyword = $_GET ['q']; //获取的q值是 "请选择" $choose="请选择"; if($keyword==$choose) echo "ok"; echo var_mp($keyword).var_mp($choose); //echo 的结果 $keyword=>string(9) "请选择" $choose=

4. PHP中文验证码只有背景没中文

中文字符串的截取要使用mb_substr()

// 设置编码,在代码107行之前加上
mb_internal_encoding("UTF-8");

// 110行
//$code.=substr($str,$Xi,2);
$code.=mb_substr($str,$Xi,2);

// 136行
//$codex=iconv("GB2312","UTF-8",substr($code,$i*2,2));
$codex=mb_substr($code,$i*2,2);

5. php 中文 验证码 乱码、、、

楼主 我怀疑是编码问题 请查看个页面是否一致 都是UTF-8比如

6. php中文验证码无法显示

session_start();
$image=imagecreatetruecolor(200,60);//创建画布
$color=imagecolorallocate($image,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255));//随机颜色
//$color=imagecolorallocate($image,255,255,255);
imagefill($image,0,0,$color);//填充颜色
//中文验证码
$fontface="simhei.ttf";//确保相同目录下有该字体
$strdb=array('好','多','人','在','学','习');
for($i=0;$i<4;$i++){
$fontsizecolor=imagecolorallocate($image,mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
$codex=iconv("GB2312","UTF-8",$strdb[mt_rand(0,5)]);//iconv不能转数组取任意下标
imagettftext($image,mt_rand(20,24),mt_rand(-30,30),(40*$i+20),mt_rand(30,35),$fontsizecolor,$fontface,$codex);//如果用$code的话就生成1+2+3+4是个汉字的验证码了

}

//干扰点
for($i=0;$i<200;$i++){
$pointcolor=imagecolorallocate($image,mt_rand(50,200),mt_rand(50,200),mt_rand(50,200));
imagesetpixel($image,mt_rand(1,100),mt_rand(1,20),$pointcolor); //雪花
}
//干扰线
for($i=0;$i<3;$i++){
$linecolor=imagecolorallocate($image,mt_rand(50,200),mt_rand(50,200),mt_rand(50,200));
imageline($image,mt_rand(1,99),mt_rand(1,99),mt_rand(1,99),mt_rand(1,99),$linecolor);
}
ob_clean();
header("Content-type:image/png");
imagepng($image);
imagedestroy($image);

7. php中文验证码转换编码iconv出问题

你好,你的字体引用的格式不对,换成

$font = $_SERVER['DOCUMENT_ROOT'].'/icon/yw.ttf';

imagettftext($im, 12, 18, 20, 20, $te, $font,'hello');


字体要是ttf的哦,希望对你有用啊!一准就好了

8. PHP图片中文验证码生成问题

重新写了一下,这里不能print那个字符串..不然会出错
因为启动了session 之前不能有输出
最终$_SESSION['yzm']就是图片上的验证码..
--------------------
<?php
session_start();
$im = imagecreatetruecolor(80,30);
$bg = imagecolorallocate($im,0,0,0);
$te = imagecolorallocate($im,255,255,255);
for($i=0;$i<5;$i++)
{
$te2 = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imageline($im,rand(0,80),0,80,rand(0,30),$te2);
}
for($i=0;$i<200;$i++)
{
imagesetpixel($im,rand()%100,rand()%30,$te2);
}
srand((float) microtime() * 10000000);
$input = array("步","步","高","请","转","到","图","像","我","非","常","高","兴");
$rand_keys = array_rand($input, 4);
$_SESSION['yzm'] = $t = $input[$rand_keys[0]].$input[$rand_keys[1]].$input[$rand_keys[2]].$input[$rand_keys[3]];
imagettftext($im,12,0,10,20,$te,'stxingka.ttf',$t);
header("content-type: image/jpeg");
imagejpeg($im);
?>

9. php 中文验证码一般用什么字体

1M左右的行吗?下载地址不好发上来,看截图吧,那个网站里再找找可能还有更小的字体文件。

10. thinkphp的验证码类库,如果需要使用中文验证码,那么需要将系统字体文件复制到

我的项目代码:

<?php
publicfunctionverify_code(){
$verify=newThinkVerify();

$verify->__set('seKey',C('VERIFY_KEY'));
$verify->__set('useZh',true);
$verify->__set('bg',array(235,246,230));
$verify->__set('length',2);
$verify->__set('fontSize',14);
$verify->__set('imageH',40);
$verify->__set('imageW',70);
$verify->__set('code',get_word());
return$verify->entry(1);
}
?>

get_word方法是随机获取一个两个字的词。

另外,字体是TP自带的。

目录在:/ThinkPHP/Library/Think/Verify/

热点内容
服务器怎么证明是好的 发布:2024-05-17 18:39:28 浏览:682
树莓派如何搭建mqtt服务器 发布:2024-05-17 18:27:38 浏览:436
门口机sip服务器ip是什么 发布:2024-05-17 17:38:27 浏览:553
光遇安卓区是什么服 发布:2024-05-17 17:22:25 浏览:24
linux驱动开发教程 发布:2024-05-17 17:19:52 浏览:501
抖音中秋节视频脚本 发布:2024-05-17 17:19:51 浏览:194
快递柜为什么用安卓系统 发布:2024-05-17 17:17:18 浏览:907
电脑配置光纤接口怎么标注 发布:2024-05-17 17:06:56 浏览:977
如何用方向键控制安卓机 发布:2024-05-17 16:38:11 浏览:199
雨田系统源码 发布:2024-05-17 16:28:06 浏览:587