[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1272
  • Last Modified:

Check if a coldfusion session still exist

Dear Experts,

Im want to properly display a list of member usernames currently online. The way that Im currently doing does not seem to work. Im using Coldfusion session to do this, here is my MSSQL database structure.

USERS TABLE:
Id (int- auto increment)
Username (varchar 20)
Password (varchar 15)
Online_status (tinyint default 0)
Session_id (varchar(50)
Session_time (smalldattime)

<CFAPPLICATION NAME="activeUser"
CLIENTMANAGEMENT="YES"
SESSIONMANAGEMENT="YES" SESSIONTIMEOUT="#CreateTimeSpan(0,0,5,0)#">

1.      when user successfully logs in:
a.      update the online_status to 1
b.      update the session_id with CFID
c.      update the session_time with timeformat(now())

When the members actually click on the logout button I simply:
2.      update online_status to 0

Now the problem is that when member DONT log out or idle for hours. Ive tried several way but had no luck, I cant seem to figure this out.

What I tried was to loop through the user table with this query below and see if there session_id still exist. But the syntax that I used was incorrect.

Select *
From users
Where online_status = 1

HELP please! Thank you in advance for your help.
0
Bradino
Asked:
Bradino
  • 7
  • 5
1 Solution
 
rob_lorentzCommented:
you need to create a stored procedure that can be scheduled to run hour, every half hour, every 10 minutes, whatever. That sp would update the online_status flag to 0 if the session time is older than 2 hours or whatever your coldFusion session timeout is set to.

in our user table we have a sessionStart time and a sessionLastRequest time. Everytime the user requests a page we verify their session and update the lastRequest time. we check the lastRequest times to determine which users are no longer attached and update/delete them.
0
 
BradinoAuthor Commented:
Rob,

Isn't  there a way to do this in the application.cfm onEndRequest? The reason why i ask is I'm unfamiliar with sp and not sure where to begin.

thank for your reply!
0
 
rob_lorentzCommented:
i dont think i would put it in the application.cfm. because that would subject all users to the check. you could do it via coldFusion in a schedule .cfm file that executes on a scheduled basis.

either way you need to add a lastRequestTime field to your users table and update it in application.cfm
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
BradinoAuthor Commented:
Rob,

I sorry, this maybe a stupid question but how do i check every time a user request a page and how do verify their session and update the lastRequest time?
0
 
BradinoAuthor Commented:
Could you please provide a sample script? Thank you!
0
 
rob_lorentzCommented:
in your application.cfm where you verify that the user is currently logged in, update their contact record with the request time.
0
 
BradinoAuthor Commented:
Here what i have in my application.cfm.

<CFAPPLICATION NAME="activeUser"
CLIENTMANAGEMENT="YES"
SESSIONMANAGEMENT="YES" SESSIONTIMEOUT="#CreateTimeSpan(0,0,5,0)#">

<CFPARAM NAME="session.Allowin" DEFAULT="false">

thats it, not sure what your saying.
0
 
rob_lorentzCommented:
<CFAPPLICATION NAME="activeUser"
CLIENTMANAGEMENT="YES"
SESSIONMANAGEMENT="YES" SESSIONTIMEOUT="#CreateTimeSpan(0,0,5,0)#">

<CFPARAM NAME="session.Allowin" DEFAULT="false">

<cfif session.allowIn>
  <cfquery name="stampUser" datasource="yourDSN">
    update userTable
   set lastRequestTime = #now()#
  where id = session.userId
  </cfquery>
</cfif>

you will have to play with the query.
0
 
BradinoAuthor Commented:
Thanks for all your help, but I'm about to just give up. I did exactly what you suggested and it's not update the lastRequestTime.


<CFAPPLICATION NAME="activeUser" SESSIONMANAGEMENT="YES" SESSIONTIMEOUT="#CreateTimeSpan(0,0,5,0)#">

<CFPARAM NAME="session.Allowin" DEFAULT="false">

<CFIF session.Allowin>
  <CFQUERY NAME="stampUser" DATASOURCE="testDSN">
    update users
         set lastRequestTime = #now()#
    where id = #session.userID#
  </CFQUERY>
</CFIF>

Question when a user link on a link on the page it should trigger the update, right?

thank again!
0
 
BradinoAuthor Commented:
I finally got it to work! Thank you for pointing me in the right direction. I was wondering if you can answer this question? is it recommended to use application.cfm or application.cfc or both?

thanks again!
0
 
rob_lorentzCommented:
we use application.cfc, gives you a bit more functionality, with the onRequestEnd, etc.

but be careful, if you do a cflocation in your code anywhere, the onRequestEnd doesnt get called. it only gets called when the request completes entirely.

0
 
BradinoAuthor Commented:
Great, thanks for the tip.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now