Php 产生中文数字字母的验证码,php生成验证码 支持中文 字母 数字混合

//验证码的制作

//1.生成4位的随机数

for($i=0;$i<4;$i++){

$rand.=dechex(rand(1, 15));

}

//2.创建图片

//创建一张图片

$image=imagecreatetruecolor(100, 30);

//背景颜色

$bg=imagecolorallocate($image, 0, 0, 0);

$te=imagecolorallocate($image, 255,255,255);

//划线

for($i=0;$i<4;$i++){

$lineColor=imagecolorallocate($image, rand(20, 225), rand(20, 225), rand(20, 225));

imageline($image, rand(0, 100), 0, 100,30, $lineColor);

}

//划点

for($i=0;$i<200;$i++){

imagesetpixel($image, rand()%100, rand()%100, $lineColor);

}

//添加文字

//编码转换

$str=iconv("GBK", "UTF-8", "广州GZ");

imagettftext($image, 12,11, 20, 20, $lineColor, 'simhei.ttf', $str);

//3.随机数写入图片$font=(1~6)

imagestring($image, rand(3, 6), rand(3, 70), rand(0, 16), $rand, $te);

//4.随机数保存在session中

//启动session

session_start();

//把验证码放入session

$_SESSION[vilidationCode]=$rand;

header("Content-type: image/jpeg");

imagejpeg($image);

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值