<?php
	$cre = $_SESSION['username'];

	include('connect.php');

	$query = "SELECT * FROM users WHERE  stid='$cre'";
	$subject_set = mysqli_query($connection,$query);
	$row = mysqli_fetch_array($subject_set);

	$user_logout = $row['stid'];

	$query = "SELECT MAX(id) as big FROM system_usage WHERE username='$user_logout'";
	$subject_set = mysqli_query($connection,$query);
	$row = mysqli_fetch_array($subject_set);

	$idd = $row['big'];

	$time = time();
    $full_date = date('Y-m-d',$time).' '.date('H:i:s',$time);

    $query ="UPDATE system_usage SET logout='".$full_date."' WHERE id='".$idd."'";
    mysqli_query($connection,$query);

	if(!isset($_SESSION["username"])) 
	{
		header('Location:../index.php');
	}
	session_start();

	unset($_SESSION['username']);//Delete the username key;
	
	//session_destroy();//This would delete all of the session keys
	header('Location:index.php');
?>