Skip to main content
October 11, 2009
Question

Set a session variable

  • October 11, 2009
  • 2 replies
  • 712 views

I am trying to set a session variable for an application in dreamweaver / CF.  I enter a field on a form and pass that on to the page that sets the variable.  The form field is EQ_type.  On the page i am using to set the session, i have the following code:

1.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2.<CFSET session.sessEQtype=#form.EQ_type# >
3.<html xmlns="http://www.w3.org/1999/xhtml">
4.<head>
5.<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6.<title>Set Session</title>
7.</head>
8.<body>
9.<p><a href="EQlist.cfm">continue</a></p>
10.<p><a href="Untitled-5.cfm">vv</a></p>
11.<cfoutput>#Session.sessEQtype#</cfoutput>
12.</body>
13.</html>

When the page opens it displays the session variable (line 11).  I did this just to make sure it was set.  Click on continue to the next page, the variable shows as 0 instead of the correct number (in this case 2)

I also have the following code in my application.cfm file:

<cfapplication name="EquipmentManager"
               ClientManagement="No"
               SessionManagement="Yes"
               SessionTimeout="#CreateTimeSpan(0,0,30,0)#"
               SetClientCookies="Yes">

Am i missing something that passes this to the next page and so on?

Obviously i am pretty new to this and i have been making pretty good progress but im dead in the water on this one.

    This topic has been closed for replies.

    2 replies

    Participant
    October 12, 2009

    I think my problem might be my application.cfm file.  Where exactly should this be located?  My site folder on my test server is c:\inetpub\wwwroot\cometers\whatever.cfm.    Also, should there be a reference to this file in the page itself?  Obviously i am new to much of this.

    The session variable works if i put the following code into the head of each of my pages:

    <cfapplication name="EquipmentManager"
                   ClientManagement="No"
                   SessionManagement="Yes"
                   SessionTimeout="#CreateTimeSpan(0,0,30,0)#"
                   SetClientCookies="Yes">

    ilssac
    Inspiring
    October 12, 2009

    The <cfapplication....> tag must be run on each and every request so that the ColdFusion server knows what application and what session the request should belong to.

    The normal way to do this is to put the tag into an Applicaiton.cfm file.  ColdFusion will automatically include the code in an Application.cfm file at the beginning of each and every request.

    The newer way to do this is with an Application.cfc file, but then you set 'this' scoped variable rather then using the <cfapplicaiton...> tag.

    The documentation gives a good explanation of all this, as I am nearly late for my train and need to dash off to catch it.

    Inspiring
    October 12, 2009

    If you put <cfdump var="session#"> at the start of the next page, what do you see?