<?php
 error_reporting(0);
	include('connection.php');
	$Entry_date=date('d-m-Y');
	session_start();
	$params = session_get_cookie_params();
setcookie("PHPSESSID", session_id(), 0, $params["path"], $params["domain"],$params['secure'], $params['httponly']);
//setcookie($name, $value = null, $expire = null, $path = null, $domain = null, $secure = null, $httponly = null);
	$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'];
		
	}
		
		
?>
