Solved

Problem with OnSessionEnd in Application.cfc

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
website file permissions 4 77
VPN Dedicated IP address question 7 45
IIS url rewrite rule for web application 3 62
SSL Certificate for IIS7 Site 2 54
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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

807 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