最近在学习如何实现登录功能,按照书上的代码制作完后发现验证码图片不显示,试了很多方法都无法显示验证码图片,于是我在网上搜了一个验证码的代码添加尝试后发现可以实现了,但是现在的问题是,数据库中的用户名和密码设置没有问题,但在登录界面输入用户名密码和验证码后无法实现登录功能,验证代码没有报错,请问可以帮我找一下到底哪里出问题了吗,我弄了一天了也弄不好。谢谢!
这个是登录界面和登陆界面的代码:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
//连接数据库
require_once'conn.php';
?>
<table width="209" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="153"><table width="209" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="33" colspan="3">用户系统:</td>
</tr>
<tr>
<td width="15"> </td>
<td width="177"><table width="180" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><table width="99%" height="100" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><table width="180" height="100" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="180" border="0" cellpadding="0" cellspacing="0">
<script language="javascript">
function chkuserinput(from){
if(from.username.value==""){
alert("请输入用户名!");
from.username.select();
return(false);
}
if(from.userpwd.value==""){
alert("请输入用户密码!");
from.userpwd.select();
return(false);
}
if(from.authcode.value==""){
alert("请输入验证码!");
from.authcode.select();
return(false);
}
return(true);
}
</script>
<script language="javascript">
function openfindpwd(){
window.open("openfindpwd.php","newframe","left=200,top=200,width=200,height=200,menubar=no,toolbar=no,location=no,scrollbars=no,location=no");
}
</script>
<form name="form2" method="post" action="chkuser11111111111111.php" onSubmit="return chkuserinput(this)">
<tr>
<td height="10" colspan="3"> </td>
</tr>
<tr>
<td width="50" height="20"><div align="right">用户:</div></td>
<td height="20" colspan="2"><div align="left">
<input type="text" name="username" size="19" class="inputcss" style="background-color: #3AB2D7"
onMouseOver="this.style.backgroundColor='#ffffff'"
onmouseout="this.style.backgroundColor='#e8f4ff'">
</div></td>
</tr>
<tr>
<td height="20"><div align="right">密码:</div></td>
<td colspan="2"><div align="left">
<input type="password" name="userpwd" size="19" class="inputcss" style="background-color: #3AB2D7"
onMouseOver="this.style.backgroundColor='#ffffff'"
onmouseout="this.style.backgroundColor='#e8f4ff'">
</div></td>
</tr>
<tr>
<td height="20"><div align="right">验证:</div></td>
<td width="66" height="20"><div align="left">
<input type="text" name="authcode" size="10" class="inputcss" style="background-color: #3AB2D7"
onMouseOver="this.style.backgroundColor='#ffffff'"
onmouseout="this.style.backgroundColor='#e8f4ff'">
</div></td>
<td width="64"><div align="left">
<img id="yanzhengma11111111111111111_img" border="1" src="./yanzhengma11111111111111111.php?r=<?php echo rand(); ?>" alt="" width="70" height="30">
<a href="javascript:void(0)" onclick="document.getElementById('yanzhengma11111111111111111_img').src='./yanzhengma11111111111111111.php?r='+Math.random() ">换一个?</a>
</p>
</div></td>
</tr>
<tr>
<td height="20" colspan="3"><div align="right">
<input type="hidden" value="<?php echo $num;?>" name="num">
<input name="submit" type="submit" class="buttoncss" value="提交">
<a href="agreereg.php">注册</a> <a href="javascript:openfindpwd()">找回密码</a>
</div></td>
</tr>
</form>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="17"> </td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
</table></td>
</tr>
这个是登陆验证代码,也没有报错:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
//连接数据库
include("conn.php");
$username=$_POST['username'];
$userpwd=md5($_POST['userpwd']);
if (isset($_REQUEST['authcode'])) {
session_start();
if (strtolower($_REQUEST['authcode'])!==$_SESSION['authcode'])
{
echo"<script>alert('验证码输入错误!');history.go(-1);</script>";
}
exit;
}
class chkinput{
var $name;
var $pwd;
function chkinput($x,$y){
$this->name=$x;
$this->name=$y;
}
function checkinput(){
include("conn.php");
$sql=mysqli_query($conn,"select * from tb_user where name='".$this->name."'");
$info=mysqli_fetch_array($sql);
if($info=false){
echo "<script language='javascript'>alert('不存在此用户!');history.back();</script>";
exit;
}
else{
if($info['dongjie']==1){
echo "<script language='javascript'>alert('该用户已经被冻结!');history.back();</script>";
exit;
}
if($info['pwd']==$this->pwd)
{
session_start();
$_SESSION['username']=$info['name'];
$producelist="";
$quatity="";
header("location:index.php");
exit;
}
}
}
}
$obj=new chkinput(trim($username),trim($userpwd));
$obj->checkinput();
?>
登录验证代码中的检验验证码这部分的代码因为之前的书上的代码的验证图片打不开,所以我把验证验证码这部分的内容重新改了一下,其余部分都是根据书上的打的,应该没有错误。
if (isset($_REQUEST['authcode'])) {
session_start();
if (strtolower($_REQUEST['authcode'])!==$_SESSION['authcode'])
{
echo"<script>alert('验证码输入错误!');history.go(-1);</script>";
}
exit;
}