html页面
ie,ff,完全就没反映,实在找不出问题。<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title></title>
</head>
<body>
<form action ="cookie_test.php" method ="post">
userID:<input type ="text" name ="user">
passwold:<input type ="password" name="password">
<input type="submit" value ="登录">
</form>
</body>
</html>php页面<?php
if($_POST[user]&&$_POST[password]){
setcookie('id',$_POST[user]);
setcookie('pwd',$_POST[password]);
}
if($_COOKIE[id]&&$_COOKIE[pwd]){
echo "登录成功<br/>";
echo "USER=".$_COOKIE[id];
echo "USER=".$_COOKIE[pwd];
}
echo "<script>location.href='cookie_test.php'</script>"
//退出不保存
/*
echo "<a href='cookie_test.php?out=out'>退出</a>"
if($_get[out]){
setcookie("id");
setcookie("pwd");
echo "<script>location.href='cookie_test.php'</script>"
}*/
?>
ie,ff,完全就没反映,实在找不出问题。<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title></title>
</head>
<body>
<form action ="cookie_test.php" method ="post">
userID:<input type ="text" name ="user">
passwold:<input type ="password" name="password">
<input type="submit" value ="登录">
</form>
</body>
</html>php页面<?php
if($_POST[user]&&$_POST[password]){
setcookie('id',$_POST[user]);
setcookie('pwd',$_POST[password]);
}
if($_COOKIE[id]&&$_COOKIE[pwd]){
echo "登录成功<br/>";
echo "USER=".$_COOKIE[id];
echo "USER=".$_COOKIE[pwd];
}
echo "<script>location.href='cookie_test.php'</script>"
//退出不保存
/*
echo "<a href='cookie_test.php?out=out'>退出</a>"
if($_get[out]){
setcookie("id");
setcookie("pwd");
echo "<script>location.href='cookie_test.php'</script>"
}*/
?>
if($_POST['user']&&$_POST['password']){
setcookie('id',$_POST['user']);
setcookie('pwd',$_POST['password']);
}
if($_COOKIE['id']&&$_COOKIE['pwd]'){
echo "登录成功<br/>";
echo "USER=".$_COOKIE['id'];
echo "USER=".$_COOKIE['pwd'];
}
echo "<script>location.href='cookie_test.php'</script>"
//退出不保存
/*
echo "<a href='cookie_test.php?out=out'>退出</a>"
if($_get[out]){
setcookie("id");
setcookie("pwd");
echo "<script>location.href='cookie_test.php'</script>"
}*/
?>
单这句就有错误:
1.结尾的;没加。
2.正确的应该是
echo "<script language='javascript'>window.location.href='cookie_test.php'</script>";
或者echo "<script type='text/javascript'>window.location.href='cookie_test.php'</script>";
$_COOKIE是接收客户端发过来的cookie信息的,虽然你setcookie('id',$_POST['user']),但这个cookie信息刚刚有服务器发往客户端的,而客户端还没有给服务器发送任何信息,所有$_COOKIE的值还没有被定义你尝试再刷新一次,这个时候就是登陆状态了,但实际的情况是你接收到的cookie是上一次的,而不是本次的