View Single Post
  #18  
Old 02-18-2008, 10:06 PM
prasannavigneshr prasannavigneshr is offline
D-Web Incredible
 
Join Date: Feb 2007
Posts: 1,264
prasannavigneshr is on a distinguished road
Send a message via MSN to prasannavigneshr
Thumbs up ColdFusion Tips & Tricks - Ending a session when the user closes their browser

Ending a session when the user closes their browser


One of the features of session variables is that the user can close their browser, shut down their computer, take a nap, power their computer back up and their shopping basket would still be there on your web site if the session timeout had not expired.

But say you don't want that. You want the session to end if they close their browser. Below is the code you need to copy-n-paste into your Application.cfm to make this happen.

How it works
Cold Fusion uses two cookies set on the user's computer, CFID and CFTOKEN, to tie them to a set of session variables. By default, these two cookies are set to never expire. By re-saving the cookies with the same name and value, any existing session variables will be maintained but the browser will set the cookies to automatically delete when the browser closes. If the user opens their browser back up and goes back to your page, the Cold Fusion server detects that there is no CFID/CFTOKEN cookies set and will generate a new combination - thus a new session.

Example HTML/CFML code:
Code:
<cfif IsDefined("Cookie.CFID") AND IsDefined("Cookie.CFTOKEN")>
    <cfset Variables.cfid_local = Cookie.CFID>
    <cfset Variables.cftoken_local = Cookie.CFTOKEN>
    <cfcookie name="CFID" value="#Variables.cfid_local#">
    <cfcookie name="CFTOKEN" value="#Variables.cftoken_local#">
</cfif>
__________________
Prasanna Vignesh
MCPD | Web Developer
Reply With Quote