We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

How can I restart a session

jtreher
jtreher asked
on
Medium Priority
207 Views
Last Modified: 2013-12-24
If the user clicks the log out button, I'm doing a structclear of the session scope. This means that any subsequent pages will not have the cfid or cftoken defined, so what I need to do is actually destroy the current session and restart a new one all in the same chunk of code. I happen to be doing this in onRequestStart

Thanks.
Comment
Watch Question

CERTIFIED EXPERT

Commented:

Why not do the structclear on a "logout" page

<cfset StructClear(session)>  of course to clear the struct
<then locate back to a home page or login or whatever>
aborting immediately after
<cfabort>

This is assuming you have some code in place that creates the session if it doesn't exist that is called when user comes to the site.

Author

Commented:
Hmmm, the URL token is the only thing that shows up in the session scope. cfid and cftoken will not recreate themselves unless the browser is shut down.

i'm calling onSessionEnd() and then onSessionStart
CERTIFIED EXPERT

Commented:
Possibly you need to recreate them manually within your onSessionEnd
jtreher, this is why the CF docs specifically warn against using the StructClear() function on the session scope.

What I do to avoid this is have all session stuff stored in a key (that is itself a structure) off the session scope.

<cfscript>
  session.user = StructNew();
  session.user.id = 0;
  session.user.username = '';
  session.user.email = '';
</cfscript>

Then, clearing the login is as simple as using StructDelete on the user key.

<cfscript>
  StructDelete(session, 'user');
</cfscript>

Then, a redirect.  Some initialization code in application.cfm detects that the user key does not exist in the session scope and recreates it and all it's keys.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Sorry about the delay, I will check into this because I really am using a substructure as well.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.