Solved

Problem with OnSessionEnd in Application.cfc

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now