当我使用标题(&#34;位置:url&#34;)时,它会将我重定向到第一页的<div>
部分(Login.php)。我可以成功验证用户名和密码,但是当我包含另一个页面进行重定向时,它无法正常工作。哪里是我的错误或我如何克服这个问题?
PHP代码(Process.php)
<?php
$mode=$_POST["mode"];
if ($mode=="check_user"){
$user_name=$_POST["user"];
$password=$_POST["password"];
$sql="Select * from user where user_name='". $user_name ."'";
$result=mysqli_query($con,$sql) or die(mysqli_error());
$record_count= mysqli_num_rows($result);
if ($record_count>0){
while($row = mysqli_fetch_array($result)){
if ($password==$row['password']){
header("Location:index.php"); //here is the problem
exit();
} else{
echo "Password Not Match";
}
}
}else{
echo "Username Not Found";
}
mysqli_free_result($result);
}
mysqli_close($con);
?>
function check_user(){
var user=$('user');
user=user.value;
var password=$('password');
password=password.value;
var myAjax = new Ajax.Updater('dvResult','process.php',{method:'post',parameters:{mode:'check_user',user:user,password:password}});
}
&#13;
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<script src="prototype.js"></script>
</script>
</head>
<body>
<center>
<form action="" method="get" name="form">
<label><b>User Name</b></label>
<input type="text" name="user" id="user"></input>
<label><b>Password</b></label>
<input type="text" name="password" id="password"></input>
<input type="button" name="login" id="login" value="Login" onClick="javascript: check_user();"></input>
<div id="dvResult"></div>
</form>
</body>
</html>
&#13;