should point out the basic logout code requires a user to click a link or something to run the structclear. it's not easily usable on browser close.
Main Topics
Browse All TopicsHello all,
I am attempting to use Coldfusion session variables within my web portal system. However I am running into a major problem when I attempt to add <cfapplication> tag into the application.cfc file. I attempted to circumvent this problem by adding the <cfapplication> tag into the code of each of the pages instead of the application.cfc. However when users log out, the session is not closed. So when a new user logs in, the session variables remain from the previous user.
I am using the default Coldfusion LDAP code created by Dreamweaver to log into and out of the portal. How can I destroy the session variable after the user logs out. Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
> <cfapplication> tag into the application.cfc
The application.cfc does not work in the same way as an application.cfm file. It does not use a cfapplication tag.
See this http://ray.camdenfamily.co
Note that the app.cfc uses the this scope to define what you would use in the cfapplication tag in a traditional application.cfm
<cfcomponent output="false">
<cfset this.name = "ApplicationName">
<cfset this.applicationTimeout = createTimeSpan(0,2,0,0)>
<cfset this.clientManagement = true>
<cfset this.clientStorage = "registry">
<cfset this.loginStorage = "session">
<cfset this.sessionManagement = true>
<cfset this.sessionTimeout = createTimeSpan(0,0,20,0)>
<cfset this.setClientCookies = true>
<cfset this.setDomainCookies = false>
<cfset this.scriptProtect = false>
<cf... other methods...>
</cfcomponent>
I would suggest you use the onSessionEnd method - this gets fired when the users browser gets closed.
On logout as Sidfishes points out create a logout.cfm page - this can do a structClear(session) and kill off all the session vars.
> I would suggest you use the onSessionEnd method - this gets fired when the users browser gets closed.
Not true. Closing the browser is a client side event, there is no way that it can communicate back to the coldfusion server to execute the onSessionEnd method. It cannot fire when the user closes the browser.
The onSessionEnd method only fires only when the session becomes inactive for the session time-out period. Note that if the application expires first, onSessionEnd will not fire, so the session timeout must be shorter than the application.
This is the code that I have within the LDAP authenication .cfc file. I am using this code to handle when some one hits the log off button in the form.
<cffunction name="logout" access="remote" output="true" hint="Log the user out.">
<cfargument name="logintype" type="string" required="yes" hint="The login type used to login.">
<cfif isDefined("form.logout")>
<cflogout>
<cfif arguments.logintype eq "challenge">
<cfset foo = closeBrowser()>
<cfelse>
<!--- replace this URL to a page logged out users should see --->
<cflocation url="http://www.google.com
<cflock scope="session" timeout="10" type="exclusive">
<cfset structclear(Divadmin)>
</cflock>
</cfif>
</cfif>
</cffunction>
I added the <cflock> tag suggested by SidFishes but I'm still getting this error when anyone attempts to logoff.
"The requested URL /?CFID=107&CFTOKEN=4161700
I'm a little lost
> "The requested URL /?CFID=107&CFTOKEN=4161700
That is error is on the google page!
This is the URL you are going to :
http://www.google.com/?CFI
Change your CFLOCATION to NOT add the CFID and CFTOKEN parameters (which it does by default) and you will just end up on the google home page.
<cflocation url="http://www.google.com
I'm getting closer to the bottom of this, however I'm, having problems with a function in my Application.cfc. The code seems to output a blank page when I run the coldfusion pages. Here's the code
<cfargument name="thePage" type="string" required="true">
<cfinclude template="mm_wizard_applic
<cfinclude template="top.cfm">
<cfif GetAuthUser() NEQ "">
<cfoutput>
<cfform action="mm_wizard_authenti
<cfinput type="submit" Name="Logout" value="Logout">
</cfform>
</cfoutput>
</cfif>
<cfreturn true>
</cffunction>
I might try something like this for Application.cfc:
<cfcomponent output="false">
<cfscript>
this.name = "Application Name";
...
</cfscript>
...
<cffunction name="onRequest" output="false">
<cfparam name="form.event" default="false">
<cfswitch expression="#form.event#">
<cfcase value="login">
<!--- Login Code --->
</cfcase>
<cfcase value="logout">
<!--- Logout Code --->
...
<!--- Clean Up --->
<cfinvoke method="onSessionEnd" component="Application">
<cfinvoke method="onApplicationEnd" component="Application">
</cfcase>
</cfswitch>
</cffunction>
<cffunction name="onSessionEnd" output="false">
<cfset structClear("session")>
</cffunction>
...
</cfcomponent>
As long as that switch statement stays small the performance hit should be minimal.
Business Accounts
Answer for Membership
by: SidFishesPosted on 2007-02-22 at 14:32:06ID: 18592214
your basic "logout"
ad/41734.h tm
<cflock scope="Session" timeout="10" type="exclusive">
<cfset structclear(session)>
</cflock>
there's a really good tut here
http://cfdj.sys-con.com/re
or
you could use j2ee session variables (set in cfadmin which are killed automatically on browser close)