Solved

Problem with OnSessionEnd in Application.cfc

Posted on 2006-06-27
2
269 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
[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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
What You Need to Know when Searching for a Webhost Provider
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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