?
Solved

Problem in mantaining login history

Posted on 2004-09-11
3
Medium Priority
?
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 500 total points
ID: 12035369
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
ID: 12035723
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
ID: 12035761
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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 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