?
Solved

Create a record in the database if session terminated

Posted on 2004-10-15
7
Medium Priority
?
150 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 9

Assisted Solution

by:Jerry_Pang
Jerry_Pang earned 195 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 180 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

Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
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.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 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