我在php中有一些代码,我想在关闭并打开浏览器后保存会话cookie。关闭浏览器后,会话未保存。好吧,我该怎么解决
if(isset($_POST['login'])) {
if (isset($_POST['remember'])) {
$password = $_POST['passwd'];
$email = $_POST['mail'];
$result = $mysqli->query("SELECT * FROM users WHERE email = '$email' AND passwd = '$password'");
$row = mysqli_fetch_assoc($result);
if ($row) {
if (!empty($_POST['remember'])) {
$result = "SELECT username FROM users WHERE email = '$email' ";
setcookie("logged_in", $email, time() + 60 * 60 * 24 * 7);
$_SESSION['logged_in'] = $row['username'];
header("Location: index.php");
}else {
if (isset($_COOKIE['logged_in'])) {
setcookie('logged_in', '');
}
header("Location: index.php");
}
} else {
#echo('<script> alert("sdada")</script>');
header("location:registration.php");
}
}
我的index.php页面
<?php
if(isset($_SESSION['logged_in'])){
echo "<li><a href='page5.php'><i class='fa fa-user'></i> ".$_SESSION['logged_in']."</a> </li>";
echo "<li> <a href='logout.php'><i class='fa fa-sign-in'></i> Logout</a> </li>";
}else{
echo "<li><a href='registration.php'><i class='fa fa-user'></i> Sign Up</a> </li>";
echo "<li> <a href='signin.php'><i class='fa fa-sign-in'></i> Login</a> </li>";
}
?>