Try this:

<cflock timeout="15" throwontimeout="No" scope="SESSION" type="EXCLUSIVE">
<cftry>
<cfscript>
variables.HoldCFID = session.CFID;
variables.HoldCFT = session.CFToken;
variables.HoldSID = session.SessionID;
variables.HoldURLT = session.URLToken;
structClear(session);
session.CFID = variables.HoldCFID;
session.CFToken = variables.HoldCFT;
session.SessionID = variables.HoldSID;
session.URLToken = variables.HoldURLT;
</cfscript>
<cfif (structKeyExists(cookie,'cfid') AND len(cookie.cfid) LT 3) OR
(structKeyExists(cookie,'cftoken') AND len(cookie.cftoken) LT 2)>
        <!---MFC: {destroy the session if the token values are blank} --->
        <cfset structClear(session)>
</cfif>
<cfcatch type="Any">
        <!---MFC: {In case the session structure was cleared without saving
the variables first} --->
        <cfset structClear(session)>
</cfcatch>
</cftry>
</cflock>

Enjoy,
Mike Chabot

http://www.linkedin.com/in/chabot

On Wed, Jun 30, 2010 at 12:40 PM, Lewis Billingsley
<[email protected]> wrote:
>
> HI Mike,
>
>    I'm interested in this too.  Please tell me about other methods to clear
> the session.
>
> Lewis
>
> On Wed, Jun 30, 2010 at 12:32 PM, Mike Chabot <[email protected]> wrote:
>
>>
>> As a side note, don't use StructClear(Session) to clear the session
>> structure because it can lead to some subtle problems. This is
>> specifically mentioned in the CF manual. There are safer methods that
>> you should be able to find and copy/paste without too much trouble.
>>
>> -Mike Chabot
>>
>> On Thu, Apr 1, 2010 at 3:51 AM, John  Barrett <[email protected]> wrote:
>> >
>> > Hi, I think that i am having an issue with onRequestStart in my
>> Application.cfc. I am trying to write a login app, which I think that should
>> work fine, but I can't get past the checkLogin page. I might be wrong but I
>> think that it is due to the onRequestStart function. Any help would be
>> great.
>> >
>> > Since I clear the session in 1 minute, I don't think that this is the
>> reason, and for the logout page, I was thinking that I can clear  everything
>> with:
>> > <<!--- logout.cfm--->
>> > <cfset StructClear(Session)>
>> > <!--- redirect the user to the home page--->
>> >
>> > The database is set up correct, and I get no errors. I feel lost on this,
>> as I can't get passed the form to login to the welcome page. I still need to
>> make the form friendly with errors message if the login fails, but I want to
>> get it working first!
>> >
>> >
>> > thanks so much for any help,
>> > Johnny
>> >
>> > here is the code
>> >
>> > <!--- Aplication.cfc--->
>> > <cfcomponent displayname="Application" output="true" hint="Handle the
>> application.">
>> >
>> >        <cfset this.Name = "login" />
>> >
>> >    <cfset this.SessionTimeout= CreateTimeSpan(0, 0, 1, 0) />
>> >    <cfset thIs.ApplicationTimeout =  CreateTimeSpan( 0, 0, 1, 0 ) />
>> >
>> >    <cfset this.SessionManagement = "yes" />
>> >    <cfset this.clientmanagement="yes" />
>> >    <cfset this.SetClientCookies = "no" />
>> >
>> >    <cffunction name="onApplicationStart" output="no" returntype="void">
>> >                <cfset REQUEST.dataSource ="my_DSN">
>> >
>> >    </cffunction>
>> >
>> >    <cffunction name="onRequestStart" output="no" returntype="void">
>> >        <!---if the user is not login in, force them to log in--->
>> >        <cfif not isDefined ("SESSION.auth.isLoggedIn")>
>> >                <!---if the user is submitting the "login" form--->
>> >            <!---include the "Login Check" to validate the user--->
>> >            <cfif isDefined("FORM.userLogin")>
>> >                <cfinclude template="loginCheck.cfm">
>> >            </cfif>
>> >            <cfinclude template="loginForm.cfm">
>> >            <cfabort>
>> >        </cfif>
>> >    </cffunction>
>> > </cfcomponent>
>> >
>> > <!--- index.cfm--->
>> > <cfquery name="getUser" datasource="myDSN">
>> >        SELECT user_id, userName, userPassword
>> >    FROM users
>> > </cfquery>
>> >
>> > <cfoutput query="getUser">
>> >        Welcome #getUser.userName#
>> > </cfoutput>
>> >
>> > <!---loginForm.cfm--->
>> > <!---
>> >        Filename - loginForm.cfc
>> >        Created by - John Barrett ([email protected])
>> >        Reason - the main loginForm for the application(included in the
>> main Application file)
>> > --->
>> >
>> >
>> > <!---if the user is submitting the "login" form--->
>> > <!---include the "Login Check" to validate the user--->
>> >        <cfif isDefined("FORM.userLogin")>
>> >        <cfinclude template="loginCheck.cfm">
>> >    </cfif>
>> >
>> >
>> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
>> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
>> > <html xmlns="http://www.w3.org/1999/xhtml";>
>> > <head>
>> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
>> > <title>Please login</title>
>> > </head>
>> >
>> > <body>
>> >        <!---start the login form--->
>> >    <cfform action="loginCheck.cfm" name="loginForm" method="post">
>> >
>> >        <cfinput type="hidden" name="userName_required" />
>> >        <cfinput type="hidden" name="userPassword_required" />
>> >
>> >
>> >        <table border="0">
>> >                <tr>
>> >                <td>username</td>
>> >                <td>
>> >
>> >                    <cfinput
>> >                        type="text"
>> >                        name="userName"
>> >                        message="Please type you username first!"
>> >                        required="yes" id="userName"
>> >                        value=""
>> >                        size="20"
>> >                        maxlength="100"
>> >                    >
>> >                </td>
>> >           </tr>
>> >           <tr>
>> >                        <td>password</td>
>> >                <td>
>> >
>> >                    <cfinput
>> >                        type="password"
>> >                        name="userPassword"
>> >                        size="12"
>> >                        value=""
>> >                        maxlength="100"
>> >                        required="yes"
>> >                        message="Please type you password first!"
>> >                    >
>> >                </td>
>> >           <tr>
>> >                <td>
>> >
>> >                    <cfinput type="submit" name="Submit" id="Submit"
>> value="Submit">
>> >                </td>
>> >           </tr>
>> >           </tr>
>> >        </table>
>> >    </cfform>
>> >
>> >
>> > </body>
>> > </html>
>> >
>> >
>> > <!---LoginCheck.cfm--->
>> > <cfquery name="getUser" datasource="my_DSN">
>> >        SELECT user_id, userName, userPassword
>> >    FROM users
>> >    WHERE userName= '#FORM.userName#'
>> >    AND userPassword= '#FORM.userPassword#'
>> > </cfquery>
>> >
>> > <!--- if the user name and password are correct--->
>> > <cfif getUser.recordcount eq 1>
>> >        <!--- remember user's logged in status --->
>> >        <!--- write user_id & userName in stucture--->
>> >        <cfset SESSION.auth = structNew()>
>> >        <cfset SESSION.auth.isLoggedIn = "yes">
>> >        <cfset SESSION.user_id = getUser.user_id>
>> >        <cfset SESSION.userName = getUser.userName>
>> >
>> >    <!--- Now that the user

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-newbie/message.cfm/messageid:5036
Subscription: http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-newbie/unsubscribe.cfm

Reply via email to