Php饼干是';t在表单操作重定向后设置


Php cookie isn't setting after a form action redirect

我正在尝试做一个"记住我"。我遇到了一个问题,因为表单操作重定向后没有设置cookie。

我知道这不是存储密码最安全的方式,但这很重要,因为这只是一个没有重要信息的简单页面。


if(isset($_POST['signin']))
{
        setcookie("cid",$id,time()+60*60);
        setcookie("cpass",$pass,time()+60*60);
        }
?>

<body>
<form action="login.php" method="post">
<hr/>
<table align="center"> 
<tr>
    <td colspan="2" align="center"><?php echo @$err;?></td>
</tr>
<tr>
    <th>Your email</th>
    <td><input type="text" name="username" placeholder="username"  value="<?php echo @$_COOKIE['cid'];?>" required/></td>
</tr>
<tr>
    <th>Your password</th>
    <td><input type="password" placeholder="password" name="password" value="<?php echo @$_COOKIE['cpass'];?>" required/>
</td>
</tr>
<tr>
    <th>Stay Signed In</th>
    <td><input type="checkbox" name="ch"/></td>
</tr>
<tr>
<td colspan="2" align="center">
    <input type="submit" name="signin" value="SignIn"/></td>
</tr>
</table>    
</form>
</body>

在中添加此行

if(isset($_POST['signin'])) 
{
    setcookie("cid",$id,time()+60*60);
    setcookie("cpass",$pass,time()+60*60);
    }
?>

login.php

由于您的表单操作是login.php


</table>    
</form>

这也是错误的,应该是

</form>
</table>