<?php
 error_reporting(0);
	include('connection.php');
	$Entry_date=date('d-m-Y');
	session_start();
	$Session_id=session_id();
	$Username=$_SESSION['username'];
 	$role=$_SESSION['role'];

	if (!isset($_SESSION['username'])) 
	{
		
		header("Location:index.php");
		
	}
	$inactive = 15000;
	if(isset($_SESSION['timeout']))
	{
		$session_life = time() - $_SESSION['timeout'];
		if($session_life >= $inactive)
  { 
  
session_destroy();
//$a="UPDATE `session` SET `logout_time`= NOW() WHERE `session_id`= '$Session_id' AND `username`='$Username'";
//echo $a;
mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE `session` SET `
logout_time`= NOW() WHERE `session_id`= '$Session_id' AND `username`='$Username'")or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));			
header("Location:index.php");		

	 }		
	}
	else
	{
	
	//echo "set time out period";
	//echo	$_SESSION['username'];
	}
	
 $_SESSION['timeout'] = time();
 $username=$_SESSION['username'];
 $Comp_query ="SELECT `session_date`,`login_time` FROM `session` WHERE `username`='$username' AND `Srno`= (SELECT MAX(`Srno`-1) FROM `session`)";
 $Comp_result=mysqli_query($GLOBALS["___mysqli_ston"], $Comp_query) or die('Query Failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
 while($count = mysqli_fetch_assoc($Comp_result))
	{
		
			
	    $Session_date=$count['session_date'];
		$Login_time=$count['login_time'];
		
	}
		
		
?>
