Log User Logout Time with PHP MySQL
This post will show you How to log User Log Out Time
Before you go through the Post , check out my Previous Post, where i have created a table name “accesslog”
This Table will log the User Login Time , User Log Out Time , ID & IP Address . etc
Prior to that you need to complete the items listed Below
Logout Script As Below
<?php // Initialize the session include ("C:/xampp/htdocs/dbconnection.php"); session_start(); $nowTimeStamp = date("Y-m-d H:i:s"); $previousStartTime = $_SESSION["startTime"]; $id = $_SESSION["id"]; $logout_Querry = "UPDATE accesslog SET timeLogout = '$nowTimeStamp' WHERE( timeLogin = '$previousStartTime ' AND userID = $id)"; if ($dbConnectionStatus->query($logout_Querry)) { echo 'Success'; } else { echo'Error'; } // Unset all of the session variables $_SESSION = array(); // Destroy the session. session_destroy(); // Redirect to login page header("location: logins.php"); exit; ?>