Solved

Create a record in the database if session terminated

Posted on 2004-10-15
7
144 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
Comment Utility
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
Comment Utility
>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
Comment Utility
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
Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

 
LVL 9

Assisted Solution

by:Jerry_Pang
Jerry_Pang earned 65 total points
Comment Utility
>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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

11 Experts available now in Live!

Get 1:1 Help Now