导航:首页 > 编程语言 > php中文随机验证码

php中文随机验证码

发布时间:2022-06-19 23:21:07

❶ 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/

❷ php如何使用随机函数rand()生成一个数字验证码

参考这个
$code="";
//画布
$image=imagecreatetruecolor(80, 25);
imagefill($image, 0, 0, imagecolorallocate($image, 255, 255, 255));

for($i=0;$i<4;$i++){
$rand_color=imagecolorallocate($image, rand(0,155), rand(0,155), rand(0,155));
$code_tmp=dechex(rand(1,15));
$code.=$code_tmp;
imagestring($image, rand(4,5), rand($i*20,$i*20+20-6), rand(0,13),$code_tmp , $rand_color);
//干扰线
imageline($image, rand($i*20,$i*20+20), rand(0,25), rand($i*20,$i*20+20), rand(0,25), $rand_color);
imageline($image, rand($i*20,$i*20+20), rand(0,25), rand($i*20,$i*20+20), rand(0,25), $rand_color);
}

//保存
session_start();
$_SESSION['yzm']=$code;
session_write_close();

header("content-type:image/png");

imagepng($image);
imagedestroy($image);

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

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

❹ 如何用PHP生成验证码

PHP生成验证码的原理:使用PHP的GD库,生成一张带验证码的图片,并将验证码保存在Session中。PHP生成验证码的大致流程有:

1、产生一张png的图片;

2、为图片设置背景色;

3、设置字体颜色和样式;

4、产生4位数的随机的验证码;

5、把产生的每个字符调整旋转角度和位置画到png图片上;

6、加入噪点和干扰线防止注册机器分析原图片来恶意破解验证码;

7、输出图片;

8、释放图片所占内存。

session_start();
getCode(4,60,20);

functiongetCode($num,$w,$h){
$code="";
for($i=0;$i<$num;$i++){
$code.=rand(0,9);
}
//4位验证码也可以用rand(1000,9999)直接生成
//将生成的验证码写入session,备验证时用
$_SESSION["helloweba_num"]=$code;
//创建图片,定义颜色值
header("Content-type:image/PNG");
$im=imagecreate($w,$h);
$black=imagecolorallocate($im,0,0,0);
$gray=imagecolorallocate($im,200,200,200);
$bgcolor=imagecolorallocate($im,255,255,255);
//填充背景
imagefill($im,0,0,$gray);

//画边框
imagerectangle($im,0,0,$w-1,$h-1,$black);

//随机绘制两条虚线,起干扰作用
$style=array($black,$black,$black,$black,$black,
$gray,$gray,$gray,$gray,$gray
);
imagesetstyle($im,$style);
$y1=rand(0,$h);
$y2=rand(0,$h);
$y3=rand(0,$h);
$y4=rand(0,$h);
imageline($im,0,$y1,$w,$y3,IMG_COLOR_STYLED);
imageline($im,0,$y2,$w,$y4,IMG_COLOR_STYLED);

//在画布上随机生成大量黑点,起干扰作用;
for($i=0;$i<80;$i++){
imagesetpixel($im,rand(0,$w),rand(0,$h),$black);
}
//将数字随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$strx=rand(3,8);
for($i=0;$i<$num;$i++){
$strpos=rand(1,6);
imagestring($im,5,$strx,$strpos,substr($code,$i,1),$black);
$strx+=rand(8,12);
}
imagepng($im);//输出图片
imagedestroy($im);//释放图片所占内存
}

❺ 怎么让php生成的验证码随机数不重复

如果要生成四位数字的验证码,则可以用函数: $srand = rand(1000,9999); 会生成在1000到9999之间的随机数字,如果要生成更多位数的数字,可以更改最孝最大值。

❻ PHP图片验证码中文内容怎么写

function image($string){
session_unregister("string");
session_register("string");
Header("Content-type:image/png");
$imageWidth=80;
$imageHeight=30;
$im=imagecreate($imageWidth,$imageHeight);
$backColor=ImageColorAllocate($im,rand(220,255),rand(220,255));
imagefilledrectangle($im,0,0,$imageWidth,$imageHeight,$backColor);

for($i=0;$i<100;$i++){
$dotColor = ImageColorAllocate($im,rand(0,255),rand(0,255),rand(0,255));
$x = rand(0,$imageWidth);$y = rand(0,$imageHeight);
imagesetpixel($im,$x,$y,$dotColor);
}
for($i=0;$i<strlen($string);$i++){
$frontColor = ImageColorAllocate($im,rand(0,120),rand(0,120),rand(0,120));
imagestring($im,10,rand(20*$i+1,20*$i+10),rand(0,5),substr($string,$i,1),$frontColor);
}
imagepng($im);

imagedestroy($im);
exit();
}
将参数传入中文字符串

❼ 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);

❽ PHP怎么实现验证码中的字母是从a-z大小写随机包含。

代码如下:
<?php
function createRandomStr($length){
$str = array_merge(range('a','z'),range('A','Z'));
shuffle($str);
$str = implode('',array_slice($str,0,$length));
return $str;
}
echo createRandomStr(4);
?>

❾ php中如何使用随机函数rand()生成一个数字验证码

如果要生成四位数字的验证码,则可以用函数:

$srand = rand(1000,9999);

会生成在1000到9999之间的随机数字,如果要生成更多位数的数字,可以更改最小、最大值。

阅读全文

与php中文随机验证码相关的资料

热点内容
python读取在线表格 浏览:999
喝什么茶能缓解压抑 浏览:865
u命令无法打开 浏览:960
vue编译后的js能爬吗 浏览:453
解压骰子推荐3代 浏览:749
安卓手机划线密码忘了怎么解锁 浏览:309
精美角度主图指标源码 浏览:278
程序员编程函数需要特别好吗 浏览:181
fue加密毛发怎么样 浏览:929
网上考学历app如何屏蔽 浏览:352
python矩阵库 浏览:160
服务器如何ping服务器 浏览:281
云服务器双机热备怎么做 浏览:100
安卓果盘高清帐号是什么帐号 浏览:548
苹果解激活锁什么叫服务器解锁 浏览:596
用海绵宝宝做解压的东西 浏览:192
大pdf文件免费转word 浏览:792
如何侵入ftp服务器 浏览:192
智行app如何查询学生票使用次数 浏览:736
程序员几年后开始有前途 浏览:126