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

Purchased ColdFusion 10: Having problem with session variables

Community Beginner ,
Jun 23, 2014 Jun 23, 2014

My Dept. has just bought CF10 and I'm finally updating my existing web app to CF10 from CF8. My First Problem with CF10 is using session variables.

When using the lower version of CF (since CF 4 to 8) I have never had any problem setting up session variables and getting or using these variables in other pages after a successful login but with CF 10 it seems setting session variables and using them in other pages are a major problems. I'm not sure where have I done wrong in the codes.

First I'm setting the session in my Application.cfc This way:

<cfcomponent displayname="Application" output="true">

  <cfset THIS.Name ="MyNewApp"/>
  <cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,20,0) />
  <cfset THIS.SessionManagement ="YES"/>
  <cfset THIS.SessionTimeout = CreateTimeSpan( 0, 0, 20, 0 ) />
  <cfset THIS.SetClientCookies = false />

<cffunction name="OnApplicationStart" access="public" returntype="boolean" output="false">

<cfset application.Main_DSN = "TESTDB">

<cfreturn true />

</cffunction>

<cffunction name="onApplicationEnd" output="false">

      <cfargument name="applicationScope" required="true">

    </cffunction>

<cffunction name="OnSessionStart" access="public" returntype="void" output="false" hint="Fires when user session initializes.">

<cfset session.loggedin = "NO">
<cfset session.username = "">
<cfset session.userrights = "">
<cfset session.usergroup = "">

</cffunction>

</cfcomponent>

After login, user is validated and set values to those session.variables:

........user validation codes here......................

<cfif mylogin NEQ true>

      <cflocation url="/login/login.cfm">

      <cfabort

<cfelse>

      <cfset session.loggedin="Yes">

      <cfset session.username="#Trim(Form.username)#">

     <CFSET qUserRights = LoginObj.getUserRights('#Trim(Form.username)#')>

     <cfset session.userrights = qUserRights><!--- it's a query --->

    <CFSET qUserGroup = LoginObj.getUserGroup('#Trim(Form.username)#')>
        <cfloop query="qUserGroup">
           <cfset session.usergroup = user_group>
           <cfbreak>
        </cfloop>

    <!--- ****************** ???????????????????????????????????????????????????????????????????????????

    When I do cfdump in at this level, I can see that all of these session variables have been assigned to their values.

    But these session variables are not accessible from other pages. Other pages still show these session variable without its value.

    So, when I use these cfdumps in the index.cfm it is shown as they're not yet assigned with any values   ****************** --->

   <cfdump var="#session.loggedin#">

   <cfdump var="#session.username#">

   <cfdump var="#session.userright#">

   <cfdump var="#session.usergroup#">

</cfif>

In index.cfm, Before Login I got:

session.loggedin = NO

session.username = ["empty string"]

session.userrights = ["empty string"]

session.usergroup = ["empty string"]

After a successful Login:

session.loggedin = NO

session.username = ["empty string"]

session.userrights = ["empty string"]

session.usergroup = ["empty string"]

Have I done something wrong? These codes work on CF8. Please help.

I need to mentioned:

CF10 is in Linux and my web app is under https not http. But these session variables should be shared bentween http and https because some older application are still in http.

TOPICS
Getting started
445
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 ,
Jun 23, 2014 Jun 23, 2014

On which page is the following code?

After login, user is validated and set values to those session.variables:

........user validation codes here......................

<cfif mylogin NEQ true>

      <cflocation url="/login/login.cfm">

      <cfabort

<cfelse>

      <cfset session.loggedin="Yes">

      <cfset session.username="#Trim(Form.username)#">

     <CFSET qUserRights = LoginObj.getUserRights('#Trim(Form.username)#')>

     <cfset session.userrights = qUserRights><!--- it's a query --->

    <CFSET qUserGroup = LoginObj.getUserGroup('#Trim(Form.username)#')>
        <cfloop query="qUserGroup">
           <cfset session.usergroup = user_group>
           <cfbreak>
        </cfloop>

    <!--- ****************** ???????????????????????????????????????????????????????????????????????????

    When I do cfdump in at this level, I can see that all of these session variables have been assigned to their values.

    But these session variables are not accessible from other pages. Other pages still show these session variable without its value.

    So, when I use these cfdumps in the index.cfm it is shown as they're not yet assigned with any values   ****************** --->

   <cfdump var="#session.loggedin#">

   <cfdump var="#session.username#">

   <cfdump var="#session.userright#">

   <cfdump var="#session.usergroup#">

</cfif>

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 Beginner ,
Jun 25, 2014 Jun 25, 2014

I solved the problem.

I inherited this codes from someone els who is no longer here and I did not see there is <cfset StructClear(session)> on top of the page

Not sure why previous programmer put this code there because it is just going to wipe out the session again once it is created.

BKBK, thank you for responding and I'm sorry for the trouble

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 ,
Jun 25, 2014 Jun 25, 2014
LATEST

It was no trouble at all. Glad to hear you solved the problem.

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