我只是不希望任何用户在登录后会从网站注销(现在我遇到了某个问题,即用户将在一段时间后注销)
这是我的代码(login.php)
if(isset($_POST['login'])){
$user_name = mysql_real_escape_string($_POST['user_name']);
$user_pass = mysql_real_escape_string($_POST['user_pass']);
$user_pass = md5($user_pass);
$admin_query = "select * from admin_login where user_name='$user_name' AND user_pass='$user_pass'";
$run = mysql_query($admin_query);
if(mysql_num_rows($run)>0){
$_SESSION['time_user_name']=$user_name;
echo "<script>window.open('index.php','_self')</script>";
}
else {
echo "<script>alert('User name or password is incorrect')</script>";
}
}
header.php
session_start();
if(!isset($_SESSION['time_user_name'])){
header("location: login.php");
}else {
include_once('connect.php');
include_once('function.php');
$user_real_name = $_SESSION['time_user_name'];
$sql = "select * from admin_login Where user_name = '$user_real_name'";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_assoc($result)) {
$user_real_id = $row["user_id"];
$user_real_email = $row["email"];
$role = $row["role"];
}
我没有时间设置时间并防止注销,任何线索
答案 0 :(得分:0)
您可以将到期时间设置为非常大的值:
//set cookie lifetime for 100 days (60sec * 60mins * 24hours * 100days)
ini_set('session.cookie_lifetime', 60 * 60 * 24 * 100);
ini_set('session.gc_maxlifetime', 60 * 60 * 24 * 100);
//maybe you want to precise the save path as well
ini_set('session.save_path', '/home/yoursite/sessions');
//then start the session
session_start();
答案 1 :(得分:0)
或者,您可以对内容属性使用持续时间很长(例如10000秒)的元标记,如下所示:
<meta http-equiv="refresh" content="10000;url=logout.php"/>