I am trying to saving the user login time in session array so that i may calculate the logout time later. My login_success file saving time in session successfully but the remaining two files are not saving the same time in sessions. Help me in finding out the problem please.
login_success.php
$sql2 = "SELECT DATE(login_time) AS date_part, TIME(login_time) AS time_part FROM log where username = '$USERNAME' ";
$res = mysqli_query($link, $sql2);
while ($row = mysqli_fetch_array($res))
{
echo $row['time_part'];
$_SESSION['time'] = $row['time_part'];
}
login.php
if(isset($_GET['action']) && $_SESSION['time'] )
{
session_destroy();
$start_time = $_SESSION['time'];
$life = time() - $start_time;
$_SESSION['life'] = $life;
header('location:session_life.php?act=life');
}
session_life.php
<?php
include_once './include/db_connection.php';
session_start();
print_r($_SESSION);
if(isset($_GET['act']))
{
if(isset($_SESSION['life']))
{
$lifee = $_SESSION['life'];
print_r($lifee);
}
}