Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Create a record in the database if session terminated

Posted on 2004-10-15
7
Medium Priority
?
151 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
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 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