Solved

Problem with OnSessionEnd in Application.cfc

Posted on 2006-06-27
2
238 Views
Last Modified: 2013-12-24
I'm trying to write to a database whenever the session ends. Basically it's just a log file, (time in and time out). The problem I'm having is it wont write to the db when the session ends. It doesn't seem to work when I use a variable containing the user id but it works fine if I hard code the id. Does anybody have any suggestions?

Code with variable:
<CFFUNCTION name="onSessionEnd">
   <cfquery name="qLog" datasource="MyDataSource">            
         UPDATE LOG
         SET
      LogOutDate = '#DateFormat(Now(),"mm/dd/yyyy")#',
      LogOutTime = '#TimeFormat(Now(),"hh:mm:ss tt")#'
         WHERE
      UserID = '#Session.UserID#' AND
      ID = (SELECT MAX(ID) FROM LOG WHERE UserID = '#Session.UserID#')
   </cfquery>
</CFFUNCTION>

Hard coded works fine:
<CFFUNCTION name="onSessionEnd">
   <cfquery name="qLog" datasource="MyDataSource">            
         UPDATE LOG
         SET
      LogOutDate = '#DateFormat(Now(),"mm/dd/yyyy")#',
      LogOutTime = '#TimeFormat(Now(),"hh:mm:ss tt")#'
         WHERE
      UserID = '12345' AND
      ID = (SELECT MAX(ID) FROM LOG WHERE UserID = '12345')
   </cfquery>
</CFFUNCTION>
0
Comment
Question by:htmoore
2 Comments
 
LVL 10

Accepted Solution

by:
rob_lorentz earned 500 total points
ID: 16995126
I suspect that you have already cleared your session variables before calling the onSessionEnd function. Also, because users can leave without logging out, via a bookmark, closing the browser, etc. your logout times will be inaccurate.

on our website we track the login start time and the time the last request was made for that session.
0
 

Author Comment

by:htmoore
ID: 16995197
Thanks Rob,
That's a good idea. I think I'll do that instead of using the onSessionEnd event. I was doing some reading on the net about the onSessionEnd event and it's a lot of talk about a bug in CF. It seems a lot of people are having issues with this event.

Anyway, thanks again for the idea.

Tom
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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

14 Experts available now in Live!

Get 1:1 Help Now