刷新验证码
来源:互联网 发布:快乐十分助赢软件 编辑:程序博客网 时间:2024/05/22 12:35
用户登录页面当点击验证码时,验证码会更新
思路步骤:1、创建好验证码
2、创建用户登录表单,当点击验证码时更换新的
1、yanzhengma.php
//当刷新页面时验证码会更新
<?php
ob_clean();
$im=imagecreatetruecolor(80,20);//创建画布
$bgcolor=imagecolorallocate($im,220,230,230);//调色
$border=imagecolorallocate($im,0,0,255);//设置边框的颜色
$tcolor=imagecolorallocate($im,255,0,0);
$green=imagecolorallocate($im,0,0xff,0);
imagefill($im,10,10,$bgcolor);//填充背景色
imagerectangle($im,1,1,79,19,$border);//绘制边框,也就是一个矩形,画布(0,0,80,20)边框(1,1,79,19)
$num = rand(48,122);
//rand产生一个随机整数rand(5,10)产生5-10的随机数包括5,10
for($i=0;$i<4;$i++){
$num_case=rand(0,2);//产生随机数0-2,根据数值的不同决定产生的是数字|小写|大写
switch($num_case){
case 0:$num=rand(48,57);break;//数字
case 1:$num=rand(65,90);break;//大写
default:$num=rand(97,122);//小写
}
$text[$i]=sprintf("%c",$num);//将随机产生的assii码转换为相应的字符
imagettftext($im,rand(10,20),rand(0,30),15*$i,20,$tcolor,"ahronbd.ttf",$text[$i]);
}//用 TrueType 字体向图像写入文本,ahronbd.ttf是一种字体格式
for($i=0;$i<100;$i++){
imagesetpixel($im,rand(1,79),rand(1,22),$green);//产生100个点
}
session_start();
$_SESSION["ckcode"]=implode($text);//保存到session中。和4logon.php$_SESSION["ckcode"]联系
header("Content-type:image/png");//设置输出类型
imagepng($im);//以PNG格式将图像输出到浏览器或文件
imagedestroy($im);//销毁图像释放内存
?>
2、denglu.php
<script language="javascript" type="text/javascript">
function refreshcode(obj,url){
obj.src=url+"?nowtime="+Math.random();//random来返回 0 到 1 之间的随机数
}
</script>
</head>
<body>
<center><h1>用户登录</h1></center>
<form action="" method="post">
用户名:<input type="text" name="username"><br>
密码:<input type="password" name="password"><br>
验证码:<input type="text" name="ckcode">
<img src="yanzhengma.php" style="cursor:pointer;" onclick="refreshcode(this,this.src);"><br><!--点击验证码会刷新,出新的验证码-->
<input type="submit" value="登录">
<input type="button" onclick="" value="取消">
</form>
<a href="2zhuce.php">注册新用户</a>
- jsp验证码刷新
- 局部刷新验证码
- 自动刷新验证码
- 局部刷新验证码
- 验证码刷新
- 验证码刷新
- jsp验证码刷新
- 验证码打击刷新
- 验证码刷新
- 验证码刷新问题
- jsp验证码刷新
- jsp验证码刷新
- jsp验证码刷新
- 验证码的刷新
- 刷新验证码
- 验证码刷新问题
- 无刷新验证码
- 无刷新验证码
- Lisp.中止(Aborts)
- 解析xml,并通过xml生成pdf文档
- UVa 10405
- 【java】IO流学习总结
- android 获取手机信息
- 刷新验证码
- 二次函数
- Android 判断程序前后台状态
- 对“为什么不喜欢用思维导图进行自考复习”的思考
- 数据库复习
- HDU 1202 The calculation of GPA
- 事业单位年节后收入支出有余额
- Android暗码启动
- python中telnetlib模块的使用