Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / March 2006



Tip: Looking for answers? Try searching our database.

Check is session structure exists

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scott_thornton - 31 Mar 2006 01:27 GMT
Hi,

How do you check to see if the session structure itself exists?
Not Nick - 31 Mar 2006 02:42 GMT
If you want to know if a session has been timed out, just look for a struct key that you have added, maybe username:

<cfif StructKeyExists(session,'username')>
Not Nick - 31 Mar 2006 02:51 GMT
More generic than what? ;)
If you want to keep track of session create/session end, you need to use a
application.cfc rather than the application.cfm, then you can specify a
function for OnSessionEnd where you can, for instance, update a stats db
Scott_thornton - 31 Mar 2006 03:00 GMT
Something more generic than having to specify a key.

Remember that a coldfusion server can serve many applications; some have
session managment, some don't. These many applications may be quite varied;
ergo they may not have single key similar across all applications.

Consider the site wide error template for example..
Not Nick - 31 Mar 2006 03:06 GMT
But the problem is (not really a oproblem) that  the session struct will start
to exist immediately when you access a page. If you time out, it will be
recreated immediately when you access the page (or app) again. You can not look
at it an find that it does not exist, it is impossible. But you will not know
what it contains.

If you want something generic, check the length of the structKeyList?
JMGibson3 - 31 Mar 2006 15:30 GMT
I assume you want to tell the user that they've been away too long and lost all
their Session values.  I did this in application.cfm as follows many years ago.
Be very careful (as described) if you choose the CFLOCATION method to inform
the user.

<CFSET wrkTOdd = 0>
<CFSET wrkTOhh = 0>
<CFSET wrkTOmm = 20>
<CFSET wrkTOss = 0>
<CFSET wrkTimeOut = #CreateTimeSpan(wrkTOdd, wrkTOhh, wrkTOmm, wrkTOss)#>
<CFAPPLICATION NAME="XXXXXX"
    SESSIONMANAGEMENT="Yes"
    loginstorage="cookie"
    SESSIONTIMEOUT=#wrkTimeOut#>
</CFIF>

<!--- All your login, etc. logic perhaps setting flags to test at bottom  --->   

<!--- Set session variables --->
<!--- Time Out control --->
<cfif not IsDefined("Session.Status")>      
    <cfset Session.Status = "Undefined"><!--- This identifies timeouts --->
</cfif>
<cfif not IsDefined("Session.TOdd")><!--- Your time out page can tell them the
settings --->
    <cfset Session.TOdd = wrkTOdd>
    <cfset Session.TOhh = wrkTOhh>
    <cfset Session.TOmm = wrkTOmm>
    <cfset Session.TOss = wrkTOss>
</cfif>

<!--- All your other session variable defaulting  --->   

   
<!--- Last thing to do in application.cfm --->

<!--- Check for Time Outs --->
<cfif Session.Status eq "Undefined">
    <!--- We know for sure the Session did NOT exist however,
       the crux of the issue is to determine under what conditions
        it's first time in (blank browser, coming in from an
        application list main menu, coming from a login page, etc.)
        and not really a time out --->
    <cfif CGI.HTTP_REFERER EQ "" OR
            varJustLoggedIn         eq "Y"            or
         Right(CGI.HTTP_REFERER, 9)  eq "index.cfm"    or
         (Not  ListGetAt(CGI.HTTP_REFERER,5,"/") EQ
                 ListGetAt(CF_TEMPLATE_PATH,6,"\"))    or
         Right(HTTP_REFERER, 12) eq "page_toc.cfm" or
         Right(CGI.HTTP_REFERER, 24) eq "page_Apps_Navigation.cfm">
        <cfset Session.Status = "Active">
    <cfelse>
        <cfset Session.Status = "TimedOut">
        <cfif Right(CF_TEMPLATE_PATH, 17)  eq "page_TimedOut.cfm">
        <!--- If you're going to setup a special page the above line is
            abolutely critical because on a CFLOCATION application.cfm
            fires a second time.  If you don't bypass on second time you
            induce a server loop.  If you don't want to chance it, put
            your timeout html in place of this if block with a CFABORT  --->
        <cfelse>
            <CFLOCATION addtoken="No" url="page_TimedOut.cfm">
        </cfif>
    </cfif>
<cfelse>
    <cfset Session.Status = "Active">
</cfif>
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.