关闭。这个问题需要details or clarity。它当前不接受答案。
是否要改善此问题?通过editing this post添加详细信息并澄清问题。
已关闭1小时前。
我可以登录我的网站,但是30分钟后我会自动登录。我在stackoverflow上找到了这段代码,该代码扩展了我的会话,但它不起作用,为什么呢?include('connect.php');
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM users WHERE username = '".$username."'";
$result = $con->query($query);
while($row = $result->fetch_object())
{
if (strcasecmp($username, $row->username) === 0)
{
$checkPassword = password_verify($password,$row->password);
if($checkPassword ){
session_start([
'cookie_lifetime' => 604800,
]);
$_SESSION['loggedIn'] = true;
$_SESSION['user'] = $row->username;
$_SESSION['admin'] = $row->admin;
$_SESSION['userpic'] = $row->userpic;
$_SESSION['displayname'] = $row->displayname;
$_SESSION['id'] = $row->id;
$now = date("H:i");
$id = $_SESSION['id'];
$sql = $con->prepare('UPDATE users SET online =? WHERE id = ?');
$sql->bind_param("si",$now,$id);
$sql->execute();
$sql->close();
$con->close();
header("Location:index.php?success");
exit();
}
else{
echo "
alert('Do you even know your password?');
window.location.href='index.php?HAHA';
";
}
}
}
为什么session_start([ 'cookie_lifetime' => 604800,]);无法处理缺少的内容?