Skip to main content
Participant
July 5, 2010
Answered

Help with Session Variables

  • July 5, 2010
  • 1 reply
  • 1320 views

It has been a long time since I used CF, probably 5 years. I remember a lot but it seems I'm forgetting something.

I have a form that accepts user data. This data gets posted and another form comes up. Prior to the CFQUERY in the in the post, I set a session variable, just before the cflocation that brings the next form.

If I take out the scflocation, I can output the session variable.

But when the 2nd form comes up, the same session variable is undefined.

Any suggestions?

Thanks.

    This topic has been closed for replies.
    Correct answer BKBK

    Page 1 is a form that accepts user data. I use email address as a key, so I pass I store it as session.email

    Page 2 includes this:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <cfif form.faction eq "sub1">

    <cfset zip3 = left(form.zip,3)>

    <cfset session.email = form.email>

    <CFQUERY NAME="xxx"

    DATASOURCE="xxx">

    INSERT INTO merchant_master (email, status, company, contact, title, address1, address2, city, state,

    zip, zip3, phone, password, website, descr, logo)

    VALUES ('#form.email#', 'active', '#form.company#', '#form.contact#', '#form.title#',

    '#form.address1#', '#form.address2#', '#form.city#', '#form.state#',

    '#form.zip#', '#zip3#', '#form.phone#', '#form.password#', '#form.website#', '#form.descr#', 'xxx')

    </CFQUERY>

    <cflocation url="merchant_setup2.cfm">

    </cfif>

    Page 3. This is where session.email ends up being undefined:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>

    <head>

    <title>page3</title>

    </head>

    <body>

    <cfoutput>#session.email#</cfoutput>

    In Page 2, the database post, if I remove the CFLOCATION, I can display the value of session.email

    I can not figure out why it becomes undefined in the following page.

    Here is the application.cfm:

    <CFAPPLICATION NAME="fortwaynesavings" SESSIONMANAGEMENT="Yes" SESSIONTIMEOUT="#CreateTimeSpan(0, 0, 20, 0)#" clientmanagement="yes">

    Thanks


    <cfif form.faction eq "sub1">

    <cfset zip3 = left(form.zip,3)>

    <cfset session.email = form.email>

    I would do this instead:

    <!--- default email or, possibly, empty string --->

    <cfset session.email = "default_email@domain.com">

    <cfif isDefined("form.faction") and form.faction eq "sub1">

        <cfset zip3 = left(form.zip,3)>

        <cfset session.email = form.email>

    <CFAPPLICATION NAME="fortwaynesavings" SESSIONMANAGEMENT="Yes" SESSIONTIMEOUT="#CreateTimeSpan(0, 0, 20, 0)#" clientmanagement="yes">

    Add applicationTimeOut for formality, something like

    <CFAPPLICATION NAME="fortwaynesavings" SESSIONMANAGEMENT="Yes"  SESSIONTIMEOUT="#CreateTimeSpan(0, 0, 20, 0)#"  applicationTimeOut="#CreateTimeSpan(1, 0, 0, 0)#" clientmanagement="yes">

    application.cfm

    Verify that the file's name is Application.cfm

    1 reply

    Inspiring
    July 5, 2010

    Suggestion number 1.  Read the source code in the file with the next form.  See if there is anything that clears the session.

    Suggestion number 2. See if the file with the next form is part of the same application as the one where you set your session variable.  If it's in a different one, check that Application.cfc file to ensure it allows session variables.

    Participant
    July 5, 2010

    Maybe it is the application.cfm that I am confused about.

    I have session management enabled.

    My understanding is that all pages in the same directory as this application.cfm (which is my only one), are part of the same application.

    Or do I need to identify the application name in each page?

    Thanks again.

    Inspiring
    July 5, 2010

    Your understanding is correct.  However, your OP left an element of doubt regarding whether both files were governed by the same application.

    To troubleshoot further, cfdump your session scope right before the cflocation tag, and then again at the very start of that other file.  That may yield more clues.