Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

How do I end a session when the user closes their browser?

Use J2EE session variables!

Note: useing J2EE session variables, you will notice that your session ends when your close the browser. Actually, your session is not ending. Instead, when you relaunch your browser, a new session is created. Therefore you cannot close your browser as a means to test this code. Instead, you must wait the complete amount of time it takes for sessions to expire in your application. (If not specified, it will default to a value set in the ColdFusion administrator - usually 20 minutes.)


This question was written by Raymond Camden.
It was last updated on September 22, 2006 at 3:17:22 PM EDT.

Categories

Application Management

Comments

Comment made by dickbob on September 23, 2006 at 7:54 AM
One thing people should know is that if you leave your browser open and the session expires, if you refresh the page a new session is started but with the original JSESSIONID value. I think this is different from using CFID & CFTOKEN which will change on a refresh.


Comment made by Monte Chan on November 3, 2007 at 10:06 PM
In one of the CF books written by Ben Forta for an older version of CF, he wrote that we can tie a CF session to a session cookie as follows,

<cfcookie name="CFID" value="#session.CFID#"> <cfcookie name="CFTOKEN" value="#session.CFTOKEN#">

My question is, which way is better? J2EE or session cookies?