在表单处理页面中的php部分添加了一句
echo "<script>location.href='login.php'</script>";
浏览器中访问login.php
结果居然是不断的打开那个url。
怎么解决?<html>
<meta http-equiv="content" content="text/html;charset=utf8">
<title>xxx</title>
</head>
<body>
<?php $Pusername=$_POST[username];
$Ppassword=$_POST[password]; setcookie('cid',$Pusername);
setcookie('cpassword',$Ppassword); //echo "<script>document.location.href='login.php'</script>"; if($_COOKIE[cid] && $_COOKIE[cpassword])
{
echo "id and password cookie has set!"."<br />";
echo "用户名:".$_COOKIE['cid']."密码:".$_COOKIE['cpassword']."<br />";
}
?>
<form action="" method="POST">
<div><a href="reg.php">还没有注册?点击注册</a>登录
<div>用户名:<input type="text" value="input your name" name="username"></div>
<div>密码:<input type="password" value="******" name="password"></div>
<div><input type="submit" value="登入"><input type="reset" value="重置"></div>
</div>
</form>
</body>
</html>
php表单
echo "<script>location.href='login.php'</script>";
浏览器中访问login.php
结果居然是不断的打开那个url。
怎么解决?<html>
<meta http-equiv="content" content="text/html;charset=utf8">
<title>xxx</title>
</head>
<body>
<?php $Pusername=$_POST[username];
$Ppassword=$_POST[password]; setcookie('cid',$Pusername);
setcookie('cpassword',$Ppassword); //echo "<script>document.location.href='login.php'</script>"; if($_COOKIE[cid] && $_COOKIE[cpassword])
{
echo "id and password cookie has set!"."<br />";
echo "用户名:".$_COOKIE['cid']."密码:".$_COOKIE['cpassword']."<br />";
}
?>
<form action="" method="POST">
<div><a href="reg.php">还没有注册?点击注册</a>登录
<div>用户名:<input type="text" value="input your name" name="username"></div>
<div>密码:<input type="password" value="******" name="password"></div>
<div><input type="submit" value="登入"><input type="reset" value="重置"></div>
</div>
</form>
</body>
</html>
php表单
浏览器中访问login.php跳转到本页面,又没加条件,当然会一直跳。
<html>
<meta http-equiv="content" content="text/html;charset=utf8">
<title>xxx</title>
</head>
<body>
<?php $Pusername=$_POST[username];
$Ppassword=$_POST[password]; setcookie('cid',$Pusername);
setcookie('cpassword',$Ppassword); if($_COOKIE[cid] && $_COOKIE[cpassword])
{
echo "id and password cookie has set!"."<br />";
echo "用户名:".$_COOKIE['cid']."密码:".$_COOKIE['cpassword']."<br />";
}
else{
echo "<script>document.location.href='login.php'</script>";//改到这里来,当用户名与密码不存在的时候跳转到登录页login.php
}
?>
<form action="" method="POST">
<div><a href="reg.php">还没有注册?点击注册</a>登录
<div>用户名:<input type="text" value="input your name" name="username"></div>
<div>密码:<input type="password" value="******" name="password"></div>
<div><input type="submit" value="登入"><input type="reset" value="重置"></div>
</div>
</form>
</body>
</html>
判断最好是在别的页面,不同的功能页面需要分开,比如login_process.php。
然后login.php意外的页面,判断是否登陆成功,如果没有就跳到login.php
login.php就不同再跳到自己页面了。
echo "<script>location.href='login.php'</script>";