Log User Logout Time with PHP MySQL

Log User Logout Time with PHP MySQL

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

    1. Mamp or xampp with phpMyAdmin install into your Computer , check out here
    2.  A Sample Database created Check out Here
    3.  New User Created . Check out Here

 

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;
?>



 

Leave a Reply

Your email address will not be published. Required fields are marked *

4 × 5 =