php实现三次登陆失败出现验证码并验证 这是错在哪了。。

<?php session_start(); if($_SESSION['yhm']!=""){header("location:index.php");}?>

<!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>
<script language="javascript">
function fun(){
if(document.form1.t1.value==""){
alert("用户名不可为空,请填写用户名!");
form1.t1.focus();
return false;
}

if(document.form1.t2.value==""){
alert("密码不可为空,请填写密码!");
form1.t1.focus();
return false;

} }
</script>
<style type="text/css">
body {
margin:0px;
}
#up{ background:#68C6E0; height:263px; width:100%;}
.logo{margin:0 auto; background:url(picture/houtbj.jpg) center bottom no-repeat; height:250px;}
#wbk{ border:#68C6E0 1px solid; height:24px; line-height:24px;}
#bottom{ margin-top:30px; }
</style>
</head>
<body>
<div id="up">
<div class="logo"></div>
</div>
<div id="bottom">
<form id="form1" name="form1" method="post" action="login_pd.php">
<?php if(!isset($session("retry_count")))
{
$session("retry_count") = 1;
}
else
{
$session("retry_count") ++;
}

?>
<table width="600" border="0" cellspacing="15" style=" margin:0 auto;">

<tr>
<td align="right">用户名:<input name="t1" type="text" id="wbk" size="28" /></td>
<td align="right">密码:<input name="t2" type="password" id="wbk" size="28" /></td>
</tr>

<?php if($session('retry_count') > 3)
{
?>

<tr>
<td align="right">验证码:<input name="number" type="text" size="28" id="wbk"/>
</td>
<td align="right">
<img style="cursor:pointer" src="admin_yzm.php" onclick="this.src=this.src+'?' + Math.random();" />
<?php }?>
<input name="imageField" type="image" id="imageField" src="picture/dengl.jpg" onclick="return fun()"/></td>
</tr>
</table>
</form>
</div>

</body>
</html>
用数据库判断好呢?还是session
好。

如果用数据库怎么写?

<?php
header("Content-Type:text/html; charset=utf-8");
session_start();
if($_SESSION['yhm']!=""){
header("location:index.php");
}?>

<!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>
<script language="javascript">
function fun(){
if(document.form1.t1.value==""){
alert("用户名不可为空,请填写用户名!");
form1.t1.focus();
return false;
}

if(document.form1.t2.value==""){
alert("密码不可为空,请填写密码!");
form1.t1.focus();
return false;

}
document.getElementById('form1').submit();

}
</script>
<style type="text/css">
body {
margin:0px;
}
#up{ background:#68C6E0; height:263px; width:100%;}
.logo{margin:0 auto; background:url(picture/houtbj.jpg) center bottom no-repeat; height:250px;}
#wbk{ border:#68C6E0 1px solid; height:24px; line-height:24px;}
#bottom{ margin-top:30px; }
</style>
</head>
<body>
<div id="up">
<div class="logo"></div>
</div>
<div id="bottom">
<form id="form1" name="form1" method="post" action="login_pd.php">
<?php if(!isset($_SESSION["retry_count"]))
{
$_SESSION["retry_count"] = 1;
}
else
{
$_SESSION["retry_count"]++;
}

?>
<table width="600" border="0" cellspacing="15" style=" margin:0 auto;">

<tr>
<td align="right">用户名:<input name="t1" type="text" id="wbk" size="28" /></td>
<td align="right">密码:<input name="t2" type="password" id="wbk" size="28" /></td>
</tr>

<?php if($_SESSION["retry_count"] > 3)
{
?>

<tr>
<td align="right">验证码:<input name="number" type="text" size="28" id="wbk"/>
</td>
<td align="right">
<img style="cursor:pointer" src="admin_yzm.php" onclick="this.src=this.src+'?' + Math.random();" />
<?php }?>
<input name="imageField" type="button" value="提交" onclick="return fun()"/></td>
</tr>
</table>
</form>
</div>

</body>
</html>追问

用数据库判断会不。

像这样的
:用户表中加一个 登陆失败次数的列 登陆失败就加1 大于3就输出验证码 登陆成功或超过指定时间就清零

追答
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-12-23
很明显,用session 好,用数据库,他这个次数在什么时候清0就是个问题。并且,如果当时错误账号的时候,就实现不了你所说的功能。session 变量应该这样用,$_SESSION["retry_count
"]
第2个回答  2014-12-23
看看PHP基础的知识啊
$_SESSION['retry_count']  这个换你代码里面的 $session('retry_count')

 数据库记录该次浏览器访问的SESSION值, 登陆成功后就清空。

第3个回答  2014-12-23
这段代码的文件名是什么,像是你$session应该是$_session追问

改了可是还不行。

你知道怎样才能 实现三次登陆失败才出现验证码吗?

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网