Solved

Problem in mantaining login history

Posted on 2004-09-11
3
192 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 125 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

717 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