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

x
?
Solved

Problem with OnSessionEnd in Application.cfc

Posted on 2006-06-27
2
Medium Priority
?
271 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
What You Need to Know when Searching for a Webhost Provider
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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