Solved

Problem in mantaining login history

Posted on 2004-09-11
3
186 Views
Last Modified: 2011-09-20
hi!!
 i am trying to maintain login history of the users who have logged in to the site. i have to save login and log out time in database. i can save login time with no problem,, the problem is that i have to save logout time too. but what if user does not logout, he just closes the window or his system gets shut down due to some reason,, what should i do in that case,,, any ideas??
all ur help is more than welcome...
regards.
0
Comment
Question by:SadafRasheed
3 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 125 total points
Comment Utility
Rather then logout time you might want to focus on a Last active time.

Or you could incorperate both and add an extra field to the table for last active.

You would then need a small include file (which would obviously be included within the main pages of your site) containing a database query to update this field with the current time for the user everytime they access a page.

To give an overview of what you would have, all the time the user is browsing the site this field will keep getting updated, when they stop browseing it will not be updated any longer so the database field will contain the time they was last active.

There are variations of this idea that you can implement such as a temporary table to storing rows of data (one added each time a user visits a page) which are deleted according to a time out period etc

Its basically the last active/timeout idea you want to focus on, as you know there is no great way of detecting when they close the browser etc (without the use of something like a pop up, not the best of methods).
0
 
LVL 2

Expert Comment

by:nowaydown1
Comment Utility
Good Day:

As the previous expert said, there really isn't any real good way to do this other than training your users to ensure they logout.  What I normally do is just develop a system that writes down when the user logs onto a page on the site.  In this way, I can record visitor information for a form of hits tracking, and know who is viewing what page when, etc.  It's a nice feature for the amount of work involved in creating such a system.  

To expound on this idea, I normally just write a function that will do an insert to a table that records a user id, a timestamp, and the name of the page they are on.  Then I call this function from each individual page.  I normally store my user ID in a session variable, so my call from each page is generally similar to something like this:

<?php

session_start();
$userID=$_SESSION['userID'];
if(empty($userID) || !isset($userID)) {
     $userID=0;     // This means they probably haven't logged in yet
}

$hTracking=new Tracking();
$hTracking->recordActivity($userID,$PHP_SELF);
?>

By using the $PHP_SELF variable, I can just copy and paste this right on the top of every page I create on the site, and not have a management nightmare on my hands.  The timestamp is generated within the recordActivity member function in this case, simply because it makes sense to do so.  

Hopefully this will bring some clarity to the idea of a very simple way to track your users through your site (and take a guess at when they most likely logged out).  

Please let me know if there is anything else that I can do to assist you.  Have a wonderful day!
0
 
LVL 4

Expert Comment

by:aratani
Comment Utility
Probably you could use some javascript to capture when the user has closed the window, and then call a php script to handle that.

<script>

window.onunload = function(){
  if(self.screenTop>9000)
    alert('Closed.');
  window.location.href = "logout.php";
}

</script>

I haven't tried that script out, but it should work.

Hope that helps

AJ
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now