Solved

Create a record in the database if session terminated

Posted on 2004-10-15
7
149 Views
Last Modified: 2013-12-24
Hi.
I have a problem.
I have a log table in my database. Every time when user login or logout of the system I check it in the database. Now I need to know if user just close his browser, and did not click logout. I think I should check if user session does not exist anymore, and run some code after that.
How can I do it?

Thanks.
Dmitry
0
Comment
Question by:oshats
[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
  • 2
  • 2
  • 2
7 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 12324811
Classic question asked over and over.

There is no good way to solve this.

You cannot tell the difference between a user taking a long time to read a page, a user who went to another site and may come back to yours and a user who has closed the browser.

None of these users logged out and in the first case they are still actively using your site.


The best you can do is guess.  If you have a login entry with no matching logout entry then after a certain amount of time you can assume they are gone.
0
 
LVL 9

Expert Comment

by:Jerry_Pang
ID: 12325725
>Now I need to know if user just close his browser, and did not click logout.
as he said, you cant.

another way is to wait for the session to expire.
or set the table an expiration timeout.

Table MonitorUser
user,timein,timeout,expiration

if the user is expired, automatically set the user as logout.
if he clicked logout, then set the timeout.

there are creative ideas to do this.
other ways is to check whether the session is exist then user is still login(even if he click logout.)
0
 

Author Comment

by:oshats
ID: 12327701
Thanks for help.

More questions.
Is there any way to detect if user leaves my domain zone?
Can I use JavaScript onUnload() or other function to detect it?

Also i am think about using Flash. For example - I have a small invisible flash object on each page. These objects call some function on the server each 5 minutes to confirm that user still here.  

OR

If use <body onUnload()>.
Every time user leaves my page I send a "OUT" key to the application. Every time page is loading, I send "IN" key. If "OUT" key is received, but "IN" key has not received in next 2-5 minutes - user did not come back.

What do you think?
Thanks.

P.S. Sorry for my English. I hope I can explain my questions in right way.
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 9

Assisted Solution

by:Jerry_Pang
Jerry_Pang earned 65 total points
ID: 12335550
>If use <body onUnload()>.

we had no luck with this approach,
problems
1. we get javascript error that the browser does not exist anymore.
2. we need to find a way to submit it back to the server, we tried
newwindow but still, if they have popup blocker or XP sp2, it wont
display or submit back. error will still occur that the window does not exist.
(sample Alt-F4, close button, or change url in browser, etc)


post back if you can do this. tell us how. =)
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 60 total points
ID: 12338870
OnUnload often has many problems.  But you can try it if you want.  However, it can be blocked, it doesn't always fire if the browser is closed, etc...
0
 

Author Comment

by:oshats
ID: 12339428
Thanks,

I am going to use flash now.

I have a small flash file, which update application variable on the server every 5 minutes.

Something like:

Application.UserID=UserID
Application.DateTime=now();

Every 1.5 minute server runs a script, something like:

<CFIF DateCompare(Application.DateTime, DateAdd(n,-15, now())) LT 0>
      <CFSET UserStatus = ‘LOGOUT’>
</CFIF>


In case user loses connection and in the time flash try to rich server, I made it 15 minutes before LOGOUT. So flash can try connect up to 3 times.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 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