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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i do a session clearing when the browser is closed ?

Status
Not open for further replies.

perichazhi

Programmer
Jul 17, 2000
25
IN
Hi all,

I am facing a peculiar problem..

I need to clear off my session variables when the user closes the browser window without doing a proper logout operation. Please, can anyone help me.

ASP uses a function called session_onend.

How can i do it in Coldfusion..

Thanx in advance..
Perichazhi
 
You can set an expiration time for you session variables through CFAPPLICATION. If you know how to do it somehow different Cfschedule is the only way to revoke a set of tags without opening a browser windows.
 
Hi. Been following this discussion with great interest. Won't the session variables automatically clear when the browser is closed? Is CFSchedule the only way? How do I use it?
 
Hi everyone,

No, by default session variables aren't expired when browsers' are closed. Here a piece of code I found that would do the trick. PUt this in your application.cfm together with CFAPPLICATION tag and your desired attribute settings.


<CFCOOKIE NAME=&quot;CFID&quot; VALUE=&quot;#Session.CFID#&quot;>
<CFCOOKIE NAME=&quot;CFToken&quot; VALUE=&quot;#Session.CFToken#&quot;>

 
Better Still:

<!--- Set Cookie to new CFID to prevent users from getting back in an Open Session, if Browser was closed. --->

<CFIF IsDefined(&quot;Cookie.CFID&quot;)>
<CFLOCK scope=&quot;SESSION&quot; timeout=&quot;10&quot; type=&quot;EXCLUSIVE&quot;>
<cfcookie name=&quot;CFID&quot; value=&quot;#SESSION.CFID#&quot;>
</CFLOCK>
</CFIF>

Use the If so it is only called when it is a new CFID.
You do not need to do the CFToken, just one will do the trick.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top