如何在12小时后取消会话?
<?php
session_start();
include 'conn.php';
$q1 = "
SELECT
id
FROM
sessions
WHERE
session_id = '".$_SESSION['session_id']."'
AND
user_ip = '".$_SERVER['REMOTE_ADDR']."'
AND
user_id = '".$_SESSION['user_id']."'
";
if(!$r1 = $Mysqli->query($q1))
{
echo 'Something wrong happend!. '. $Mysqli->error;
}
?>
的login.php
<?php
include('check.php');
include('header.php');
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$login_user = $Mysqli->real_escape_string($_POST['gebruikersnaam']);
$login_pass = $Mysqli->real_escape_string(sha1($_POST['wachtwoord']));
$user_ip = $_SERVER['REMOTE_ADDR'];
srand ((double) microtime( )*1000000);
$session_id = rand(1000,1000000);
$q1 = "
SELECT
id,
username,
block
FROM
users
WHERE
username = '".$login_user."'
AND
password = '".$login_pass."'
";
if(!$r1 = $Mysqli->query($q1))
{
echo 'Er is een fout opgetreden!. '. $Mysqli->error;
}
elseif($Mysqli->affected_rows == 1)
{
while ($row = $r1->fetch_assoc ())
{
$_SESSION["username"] = $row['username'];
$_SESSION['user_id'] = $row['id'];
$_SESSION['user_ip'] = $user_ip;
$_SESSION['session_id'] = $session_id;
if ($row['block'] == 1)
{
echo 'Je bent geblokkeerd, je kunt niet meer inloggen!';
}
else
{
//Inloggen gelukt!!
echo 'U bent ingelogd, <a href="index.php">Klik hier</a>';
}
$q2 = "
INSERT INTO
sessions
(
user_id,
session_id,
user_ip
)
VALUES
(
'".$row['id']."',
'".$session_id."',
'".$user_ip."'
)
";
}
if (!$Mysqli->query ($q2) )
{
echo 'Er is een fout opgetreden!'. $Mysqli->error;
}
}
else
{
echo 'Gebruikersnaam of wachtwoord onjuist, probeer het opnieuw!';
}
}
else
{
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<?php
if(isset($_GET['error']))
{
if($_GET['error'] == 'sess')
{
echo 'De sessie is ongeldig! Log aub opnieuw in!<p>';
}
}
?>
<form method='post'>
<table>
<tr>
<td>Gebruikersnaam:</td>
<td><input type='text' name='gebruikersnaam'></td>
</tr>
<tr>
<td>Wachtwoord:</td>
<td><input type='password' name='wachtwoord'></td>
</tr>
<tr>
<td><input type='submit' name='submit' value='Login'></td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
include('footer.php');
?>
在反应中是 的ini_set(&#39;的session.gc_maxlifetime&#39; 60 * 12);
我在哪里放置它?和选项2我可以在哪里放置?
你能帮帮我吗?如果您需要更多信息,请询问。答案 0 :(得分:0)
设置12小时后删除会话的时间。
方法1:
ini_set('session.gc_maxlifetime',60*12);// 60 minutes * 12
方法2:
<?php
$inactive = 3600 * 12;// 12 hours
$session_life_sid = time() - $_session['timeout'];
if($session_life_sid > $inactive)
{
session_destroy();
session_unset();
}
$_session['timeout']=time();//Set this timeout session when you are setting session for session_id and user_id