Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with Session Variables

New Here ,
Jul 05, 2010 Jul 05, 2010

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.

1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 07, 2010 Jul 07, 2010
<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 applicatio

...
Translate
LEGEND ,
Jul 05, 2010 Jul 05, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 05, 2010 Jul 05, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 05, 2010 Jul 05, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 05, 2010 Jul 05, 2010

For some reason, about 1/2 of my forms are

treated as a different application.

It has been about 5 years since I used CF. Has there been something changed? Do I need to add something to each form to force them to be seen as the same application?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 06, 2010 Jul 06, 2010

Are all these templates in the same dir or a subdir of the one with the Application.cfm file in it?

Can you post the <cfapplication> line from said Application.cfm?

--
Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2010 Jul 07, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 07, 2010 Jul 07, 2010

When you <CFDUMP VAR="#SESSION#"> at the top of the third page, what shows up?  Is it a blank structure, or does it show session ID and token data?  If you put the cfdump before the CFLOCATION and comment-out the CFLOCATION, does that dump show the same session ID?

For grins and giggle, try putting addtoken="No" in the CFLOCATION tag to see if that changes things.

-reed

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 07, 2010 Jul 07, 2010
<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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2010 Jul 07, 2010
LATEST

Thank you for all of your help. Now I feel dumb. Chnaging application.cfm to Application.cfm took care of it. I'll do some more reading on Application.cfm.

All of your answers will help me better debug other things later on.

Thanks again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources