Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Capabilities & Limitations...

Status
Not open for further replies.

tweekerbythespeeker

Programmer
May 4, 2004
3
US
This is more of a general consideration and query to all who know more than I. Heres the deal...

1. a session is created for a unique user when they log on to an online application
2. When they log on, a value is changed from '0' to '1' in a DB (upon this is based a "whos online search"). So obviously in a perfect world, when they are finish(and or session times out), the value is changed back to '0'. This is easy if they click "log-off". In that case I just use the "structure(clear)" and a simple UPDATE query to achieve the desired result. I can also achieve the desired results if the user's session timesout while ON MY SITE with some "if thens", and a cookie read in on my "application.cfm" page.

The code on my application.cfm page is below.........

3. 2 situations need to be accounted for though:
- when the user does not log off, browses to another site and their session times out. This is ONLY ACTUALIZED UPON RETURN... if the user goes astray and timesout while gone... they are still considered online while at different websites. The value is only changed back to '0' when they return. Only THEN is the "application.cfm" page able to check out the situation and act accordingly on the lack of values for 'session.loggedin' and 'cookie.test' (this cookie is created at login and only contains the user's unique ID for the changing of the value "prf_online")
-this is true for the closing of the browser part too. If they close the browser... It is working in theory, but not actualized until they go back and application.cfm is able to do its thang.


Does anyone have light to shed? I feel like there must be a more efficient way of doing a "Whos online search"....?

thnks -- joe

-------------------------------------------------------


<!-- basically saying, if they have logged on
(hence the cookie), and their sesh has expired
change the value and kill the cookie. this part
works well is they stay on the site and dont
browse away before timoeout-->
<cfif NOT isDefined('session.loggedin') AND isDefined('cookie.test')>
<cfquery name="updateVals" datasource="dudefinders">
UPDATE cs_tbl_profiles
SET prf_online= '0'
WHERE ID = #cookie.test#
</cfquery>
<cfcookie name="test" expires="now">
</cfif>


<!-- for browser closing -->
<cfif IsDefined("Cookie.CFID") AND IsDefined("Cookie.CFTOKEN")>
<cfset cfid_local = Cookie.CFID>
<cfset cftoken_local = Cookie.CFTOKEN>
<cfcookie name="CFID" value="#cfid_local#">
<cfcookie name="CFTOKEN" value="#cftoken_local#">
<!-- from above -->
<cfif NOT isDefined('session.loggedin') AND isDefined('cookie.test')>
<cfquery name="updateVals" datasource="dudefinders">
UPDATE cs_tbl_profiles
SET prf_online= '0'
WHERE ID = #cookie.test#
</cfquery>
<cfcookie name="test" expires="now">
</cfif>
</cfif>

 
Ok, here's how I'd do it..

On each page, set a db field LastLoggedIn to the current time.. and then in your "who's online search" you can run this where clause.

Code:
 where UserTable.LastLoggedIn > #DateAdd("n",-15,Now())#

That specifies last logged in in the last fifteen minutes..

With dateadd, the first argument is the datepart.. N stands for minute because M stands for month... -15 tells it to subtract 15 of datepart (in this case minutes) from the third argument (Now())

A slightly more complex method but less db-load-intensive would be to also set it in a cookie and when the cookie time is older than five minutes, reset the cookie to #Now()# again and update the time in the database. So at most it only gets updated for the user every ten minutes.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
thanks bro!!! I ended up using that dateAdd function in a slightly different way. if you are interseted ill post it.. otherwise much thanks and respect. peace out
 
Sure,

I'm not sure I'd have a use for it, but dude, TT is all about sharing... share with other programmers what your solution was.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top