Cookie未设置。 setcookie()结构对我来说看起来很合适,但由于某种原因,我无法让它工作。下面是我使用的形式:setcookie()不能从登录表单工作
if(isset($_POST['LoginBtn']))
{
$username = mysql_escape_string($_POST['username']);
$password = mysql_escape_string($_POST['password']);
if($_POST['remember_me']==1){
$twoDays = 60 * 60 * 24 * 300 + time();
setcookie('UserLogin', $username, $twoDays);
setcookie('UserPass', $password, $twoDays);
}
echo '<script>window.location="index.php"</script>';
}
?>
<html>
<head>
<title>Log In</title>
</head>
<body>
<form method="post" action="login2.php">
<input type="text" name="username" value="<?php echo $_COOKIE['UserLogin'];?>" />
<input type="password" name="password" value="<?php echo $_COOKIE['UserPass'];?>" />
<input type="checkbox" name="remember_me" value="1"/> Remember Me
<input type="hidden" name="LoginBtn" value="1" />
<button type="submit">Login Now</button>
</form>
而且这里是我试图饼干呼应的索引页:
<?php
echo "<br />cookie user_name: ".$_COOKIE['UserLogin'];
echo "<br />cookie user_pass: ".$_COOKIE['UserPass'];
echo "<br /><a href='login2.php'>Back</a>";
?>
你有没有在浏览器中的cookie检查是否产生或不? –
请勿使用'mysql_'功能。他们不会在当前的PHP版本中工作。它只用于石器时代的PHP。 – DanFromGermany