Session_Session与图片验证码结合使用

Session与图片验证码结合使用

<?php
/*
创建随机数-> 写入session ->写入图片
1 imagereatetruecolor新建一个真彩色图像
imagecreatetruecolor(int x_size,int y_size) //x就是宽,y就是高
2 imagecolorallocate为图像分配颜色
imagecolorallocate(resource image,int red,int green,int blue)
3 imagestring绘图函数
imagestring(resource image,font,int x,int y,内容,颜色)
4 dechex()转换成16进制数
5 rand()生成随机数
-->
*/
session_start();//启用session
///************生成4位16进制随机数***********/
for($i=0;$i<4;$i++){
$rand.= dechex(rand(1,15));
}

//写入session
$_SESSION[check]=$rand;


$img=imagecreatetruecolor(100,30);
//设置颜色
$bg = imagecolorallocate($img,0,0,0);//第一次用调试版的时候是背景颜色
$white=imagecolorallocate($img,255,255,255);

//将字符串写在图像上面
imagestring($img,rand(2,6),rand(1,60),rand(1,15),$rand,$white);

//输出图像
header ("Content-type: image/jpeg");
imagejpeg($img);
?>

运行结果:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值