导航:首页 > 编程语言 > php点击更换验证码

php点击更换验证码

发布时间:2022-06-09 18:36:41

A. php 验证码类,怎么改变验证码形状

直接上代码:
复制代码 代码如下:
//验证码类
class ValidateCode {
private $charset = '';//随机因子private $code;//验证码
private $codelen = 4;//验证码长度
private $width = 130;//宽度
private $height = 50;//高度
private $img;//图形资源句柄
private $font;//指定的字体
private $fontsize = 20;//指定字体大小
private $fontcolor;//指定字体颜色
//构造方法初始化
public function __construct() {
$this->font = dirname(__FILE__).'/font/elephant.ttf';//注意字体路径要写对,否则显示不了图片}
//生成随机码
private function createCode() {
$_len = strlen($this->charset)-1;
for ($i=0;$i<$this->codelen;$i++) {
$this->code .= $this->charset[mt_rand(0,$_len)];}
}
//生成背景
private function createBg() {
$this->img = imagecreatetruecolor($this->width, $this->height);$color = imagecolorallocate($this->img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color);}
//生成文字
private function createFont() {
$_x = $this->width / $this->codelen;
for ($i=0;$i<$this->codelen;$i++) {
$this->fontcolor = imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height / 1.4,$this->fontcolor,$this->font,$this->code[$i]);}
}
//生成线条、雪花
private function createLine() {
//线条
for ($i=0;$i<6;$i++) {
$color = imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);}
//雪花
for ($i=0;$i<100;$i++) {
$color = imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);}
}
//输出
private function outPut() {
header('Content-type:image/png');
imagepng($this->img);
imagedestroy($this->img);
}
//对外生成
public function doimg() {
$this->createBg();
$this->createCode();
$this->createLine();
$this->createFont();
$this->outPut();
}
//获取验证码
public function getCode() {
return strtolower($this->code);
}
}
输出实例:
使用方法:
1、先把验证码类保存为一个名为 ValidateCode.class.php 的文件;2、新建一个名为 captcha.php 的文件进行调用该类;captcha.php
复制代码 代码如下:
session_start();
require './ValidateCode.class.php'; //先把类包含进来,实际路径根据实际情况进行修改。
$_vc = new ValidateCode(); //实例化一个对象$_vc->doimg();
$_SESSION['authnum_session'] = $_vc->getCode();//验证码保存到SESSION中3、引用到页面中,代码如下:
复制代码 代码如下:
<img title="点击刷新" src="./captcha.php" align="absbottom" onclick="this.src='captcha.php?'+Math.random();"></img>
4、一个完整的验证页面,代码如下:
复制代码 代码如下:
<?php
session_start();
//在页首先要开启session,
//error_reporting(2047);
session_destroy();
//将session去掉,以每次都能取新的session值;//用seesion 效果不错,也很方便
?>
<html>
<head>
<title>session 图片验证实例</title>
<style type="text/css">
#login p{
margin-top: 15px;
line-height: 20px;
font-size: 14px;
font-weight: bold;
}
#login img{
cursor:pointer;
}
form{
margin-left:20px;
}
</style>
</head>
<body>
<form id="login" action="" method="post">
<p>此例为session验证实例</p>
<p>
<span>验证码:</span>
<input type="text" name="validate" value="" size=10>
<img title="点击刷新" src="./captcha.php" align="absbottom" onclick="this.src='captcha.php?'+Math.random();"></img>
</p>
<p>
<input type="submit">
</p>
</form>
<?php
//打印上一个session;
//echo "上一个session:<b>".$_SESSION["authnum_session"]."</b><br>";$validate="";
if(isset($_POST["validate"])){
$validate=$_POST["validate"];
echo "您刚才输入的是:".$_POST["validate"]."<br>状态:";if($validate!=$_SESSION["authnum_session"]){//判断session值与用户输入的验证码是否一致;echo "<font color=red>输入有误</font>";
}else{
echo "<font color=green>通过验证</font>";}
}
?>

B. php中如何刷新验证码

我做的一个简单的登录界面有刷新验证码还有注册功能 希望对LZ有帮助
这个是登录界面 land.php
<?php
@include_once('global.php');
session_start();
$user = $_POST['username'];
$sql = sprintf("select * from `p_admin` where `username` = '%s'",$user);
//echo $sql;
$query = $db->query($sql);//调用golbal里面的$db类
$fetch = $db->fetch_array($query);
if($_POST['sccode']==$_SESSION['rand']){
$state = $fetch ? md5($_POST['password'].$extra)==$fetch['password']:FALSE;//是否登录成功 如果失败了返回为空echo $state没有结果
if(!$state)
echo"<script language=javascript>alert('用户名或密码错误');</script>";

else {
$_SESSION['id'] = $fetch['m_id'];
$_SESSION['shell'] = md5($fetch['username'].$fetch['password']);
$_SESSION['ontime'] = time();
//echo $_SESSION['id']."<br>";
//echo $_SESSION['shell'];
$action = new action();
$action ->get_show_msg('admin/admin_main.php', $show = '操作已成功!');
}
}else
echo "<script language=javascript>alert('验证码错误');</script>";

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>

<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>用户登录</title>
<link href="style/global.css" rel="stylesheet" type="text/css">
<link href="style/link.css" rel="stylesheet" type="text/css">
<link href="style/layoutid.css" rel="stylesheet" type="text/css">
<script language="javascript">
function chform (obj) {
if (obj.username.value == "") {
alert("请输入用户名!");
obj.username.focus();
return false;
}
if (obj.password.value == "") {
alert("请输入密码!");
obj.password.focus();
return false;
}
if (obj.sccode.value == "") {
alert("请输入验证码!");
obj.sccode.focus();
return false;
}
return true;
}
function RefreshImage(id)
{
document.getElementById(id).src ='Confirm.php?'+Math.random(1);
}
</script>
</head><body>
<!--用户登录开始-->
<div class="login">
<form id="form1" name="form1" method="post" action="" onsubmit="return chform(this)">
<ul>
<li class="loginbtbj fright" style="background-image: url("images/hydl.gif");"><a title="" href="javascript:%20close();"><img src="images/close.gif" alt="关闭" align="right" border="0" height="18" width="18"></a></li>
<li class="fyellowxx fcenter">
.............................................................................................................
</li>
<li class="padleft43">
用户名:<input name="username" size="15" style="width: 150px;" type="text">
</li>
<li class="padleft43">
密码:<input name="password" size="15" style="width: 150px;" type="password">
</li>
<li class="padleft43">
验证码:<input name="sccode" size="6" style="width: 50px;" type="text"><img id="re_confirm" onclick="RefreshImage('re_confirm')" src="Confirm.php">
<a title="看不清?" href="#" onclick="RefreshImage('re_confirm')">看不清?</a> <a href=register.php >注册</a>

</li>
<li class="fyellowxx fcenter">
.............................................................................................................
<br>
<input name="Submit" src="images/dl.gif" style="border: 0pt none; width: 80px; height: 31px;" type="image">
</li>
</ul>
</form>
</div>
<!--用户登录结束-->
</body></html>
这个是验证码的程序 confirm.php 图片什么的代码我就不穿了 LZ可以借鉴下 有一点需要注意 就是这个confirm文件里面不能报错 我在这卡了很久
因为header这个之前不能输出文本 所以如果报错 就会无法显示验证码
<?php
session_start();
$random='';
for($i=1;$i<5;$i++){
$random .= dechex(rand(1,15));}
$_SESSION['rand']=$random;
$im = imagecreatetruecolor(40,20);
$bg = imagecolorallocate($im,0,0,0);
$te = imagecolorallocate($im,255,255,255);
imagestring($im,rand(1,6),rand(1,6),rand(1,6),$random,$te);
header("Content-type: image/jpeg");
imagejpeg($im);
?>

C. phpweb 网站进入后台的时候:请输入和图片上显示一致的验证码,点击验证码图片可更换一张。可我没输错。

终结版:
1时间,时区设置是否正确。
2清空浏览器缓存。
3你是否通过路由器上网,请去掉路由器试试,如果可以,请升级路由器固件或者更换路由器。
我估计你那个是第三条了

D. php源码手机验证更换成邮箱验证

这个不是几行代码就能给出结果的事。
1:将原代码里的手机验证去掉。
2:添加phpmailer,并用一个自己的邮箱作为发信箱
3:用户在注册时,要求其填写邮箱
4:用户提交注册信息,POST处理完成后,发送一封邮件到其填写的注册邮箱

验证有两种办法:
1:发送一个系统生成的字符串(一般3-6位数字即可),用户在邮箱中查看到邮件后,进行复制粘贴激活
2:发送一个特定的URL到邮箱,用户点击该URL,即可完成激活

E. phpweb 网站进入后台的时候:请输入和图片上显示一致的验证码,点击验证码图片可更换一张。可我没输错

大哥 我可以很明确的告诉你 如果一个问题在网络讨论的很少 这个问题除非特别特别难 不过大多应该基本不是问题 可能会难住你一阵子 但最后你解决后你才会发现这个问题你多么的简单 自己是多么的愚蠢 思路想错了 呵呵 所以你这个问题很容易找到答案 你整了一堆没用的 一句话本地网络的原因 网络不给力 我很怀疑你的验证码是不是没用同步 你每次输入的验证码其实已经变了 建议你在拼音的时候输入 别用搜狗打字母然后按enter输验证码 这样验证码会跳一次 会改变 如果你网络不行没有刷新你就看不到 自然会错 如果你用搜狗输入法 你先点击一下shift然后输入验证码 输入后你用鼠标点击登录 别按到enter键了 不然验证码会跳的 别瞎折腾了 问题没那么严重 不要轻易装系统 电脑里面装的软件重装一次不容易

F. php文件如何通过点击一个链接刷新验证码

差不多是一样的的道理,只是更新的是图片的src,获取对象的时候改一下就行了。

jquery代码:

<aherf="#"onclick="$('#vdimgck').attr('src','code.php?'+Math.random())">换一张</a>

G. php点击刷新验证码

第二个 onclick 事件写的不对。真确写法如下

<ahref="#"onclick="document.getElementById('code').src='code.php?tm='+Math.random()">看不清楚,刷新</a>

你貌似没搞清楚 js 里面的this 到底是什么,所简单点 this 写在哪个标签里,指的就是那个标签。

H. php中验证码的那个“换一张”的链接怎么写

基本思路就是,写个Ajax,当点击“换一张”时,请求一个生成验证码的PHP程序文件。当请求成功时,用Javascript代码把验证码替换诚心的就可以了。

I. 用php程序的jquery控制点击更换验证码浏览器不兼容问题

1. 换验证码的时候,验证码生成地址后面国加一个随机数
2. 如果是a标签为点击的话,href设为#
eg.
<img src="vimg.php" id="vpic" width="150" height="50" />
<a href="#" onclick="reload()">看不清楚? 换一个</a>
<script type="text/javascript">
function reload(){
var cpt = document.getElementById('vpic');
var src = cpt.src;
cpt.src = src+'?'+Math.random();
}
</script>

J. PHP验证码 实现点击刷新

随机产生的验证码放在一个文件1中
在另一个文件中引用文件1
<img src="code.php" onClick="this.src='code.php?nocache='+Math.random()" style="cursor:hand" alt="点击换一张"/>

实现点击图片自动刷新图片

阅读全文

与php点击更换验证码相关的资料

热点内容
stc8单片机串口中断 浏览:954
信号分析pdf 浏览:927
暴力删除命令 浏览:803
qt如何编译加快速度 浏览:903
php添加数据sql语句 浏览:717
免费的小说app有什么 浏览:405
螺杆压缩机进气阀动画 浏览:651
两台服务器如何做负载均衡 浏览:227
程序员的工资是涨的吗 浏览:813
视频存储服务器可以干什么 浏览:463
创建文件夹安装失败怎么回事 浏览:832
程序员高考隔了几年 浏览:822
云服务器是哪一层 浏览:22
jit编译器的jit什么意思 浏览:330
我想清理手机中空白文件夹 浏览:976
电脑e盘文件夹删不掉怎么办 浏览:607
外圆凹圆弧编程 浏览:461
html5编程题 浏览:840
干燥机制冷压缩机一开就跳动 浏览:389
吉林压缩空气流量监测 浏览:618