<?php
session_start();
include("conn.php");
$user=$_POST['user'];
$pwd=$_POST['pass'];
$yzm=$_POST['yzm'];
if($_POST['btnLogin']){
$sql="select * from `access` where `name`='$user' and `pwd`='$pwd'";
$rs=mysql_query($sql);
$result=mysql_fetch_array($rs);
if($result){
header("location:list.php");
$_SESSION[user]=$user;
}else{
echo "用户名或密码错误!";
}
}
?>
<html>
<head>
<title>添加留言</title>
</head>
<script language="javascript">
function check(){
if(document.login.user.value==""){
alert("用户名不能为空!");
login.user.focus();
return false;
}
if(document.login.pass.value==""){
alert("密码不能为空!");
login.pass.focus();
return false;
}
if(document.login.yzm.value==""){
alert("验证码不能为空!");
login.yzm.focus();
return false;
}
if(document.login.yzm.value!=document.login.hide.value){
alert("验证码错误!");
login.yzm.focus();
return false;
}
}
</script>
<body>
<?php
include("top.html");
?>
<center>
<table border="1">
<form name="login" method="post" action="login.php" onsubmit="return check()">
<tr>
<td>昵称:</td>
<td><input type="text" name="user"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td>验证码:</td>
<td><input type="text" size="4" name="yzm" ><img src="imagecode.php"></td>
<input type="hidden" name="hide" value="<?php echo $_SESSION['check_pic']?>">
<?php echo $_SESSION['check_pic']?>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="btnLogin" value="登录">
<input type="reset" name="btnCancel" value="取消"> <a href="reg.php">注册</a>
</td>
</tr>
</form>
</table>
</center>
</body>
</html>
为什么在验证验证码的时候程序不能正确验证,请各位高手相助
session_start();
include("conn.php");
$user=$_POST['user'];
$pwd=$_POST['pass'];
$yzm=$_POST['yzm'];
if($_POST['btnLogin']){
$sql="select * from `access` where `name`='$user' and `pwd`='$pwd'";
$rs=mysql_query($sql);
$result=mysql_fetch_array($rs);
if($result){
header("location:list.php");
$_SESSION[user]=$user;
}else{
echo "用户名或密码错误!";
}
}
?>
<html>
<head>
<title>添加留言</title>
</head>
<script language="javascript">
function check(){
if(document.login.user.value==""){
alert("用户名不能为空!");
login.user.focus();
return false;
}
if(document.login.pass.value==""){
alert("密码不能为空!");
login.pass.focus();
return false;
}
if(document.login.yzm.value==""){
alert("验证码不能为空!");
login.yzm.focus();
return false;
}
if(document.login.yzm.value!=document.login.hide.value){
alert("验证码错误!");
login.yzm.focus();
return false;
}
}
</script>
<body>
<?php
include("top.html");
?>
<center>
<table border="1">
<form name="login" method="post" action="login.php" onsubmit="return check()">
<tr>
<td>昵称:</td>
<td><input type="text" name="user"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td>验证码:</td>
<td><input type="text" size="4" name="yzm" ><img src="imagecode.php"></td>
<input type="hidden" name="hide" value="<?php echo $_SESSION['check_pic']?>">
<?php echo $_SESSION['check_pic']?>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="btnLogin" value="登录">
<input type="reset" name="btnCancel" value="取消"> <a href="reg.php">注册</a>
</td>
</tr>
</form>
</table>
</center>
</body>
</html>
为什么在验证验证码的时候程序不能正确验证,请各位高手相助
那你alert()那两个验证码看看情况
如果不一样的话可能是浏览器缓存的问题
验证码验证最好在PHP程序里进行。要在客户端进行的话,就用AJAX,来验证,但提交程序里也还是要验证的。
你这样做,要验证码何用???