Solved

Create a record in the database if session terminated

Posted on 2004-10-15
7
145 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
  • 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
Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why addon domain redirects to the original domain? 8 62
how to enable php7 module in nginx configuration file 8 334
JKS to store upstart data 2 85
System Analysis 5 51
This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

16 Experts available now in Live!

Get 1:1 Help Now