Skip to main content
June 16, 2009
Question

Session variable assingment issue

  • June 16, 2009
  • 2 replies
  • 1620 views

I am having issues with Session variables since I am not able to set a session variable. My company Intranet page checks for a session variable and then allows users to login. Please if any one can help me with code or guide what I am doing wrong.

I have tried updating session variable in application.cfm but so far no luck..

 

Auth.cfm

<cfapplication name="LID"

               ClientManagement="No"

               SessionManagement="Yes"

               SessionTimeout="#CreateTimeSpan(0,0,30,0)#"

               SetClientCookies="No">

<cflock scope="session" timeout="30" type="ReadOnly">

        <cfset Session.LID="#cflogin.name#">

     

        </cflock>

                        <cfset Session.USERID= "Request.ses.LID"> ( Session.USERID is set to check user and allow their access)

This topic has been closed for replies.

2 replies

Inspiring
June 22, 2009

One thing that I've found useful to do in my apps (corny though it may sound) is to define a variable "Session.exists = 'yes'."

Then, at the top of all of the relevant pages, I check (using StructKeyExists) to make sure that the Session object has an "exists" member.  If it does not, then I know that either the session has not been started, or it has expired.  And I redirect the user someplace to handle it.

That "someplace" is a cfm that the user ordinarily would never see.  And before I go there, I set another dummy value (say, "Session.foo") in some session-variable.  Thus, when we arrive at that "someplace":

  1. If we are here, then it's because the session expired or could not be established.
  2. If we are here, and Session.foo does exist, then it was an ordinary timeout.  We delete the Session.foo variable, then redirect to a login screen with an appropriate message.
  3. If we are here, but Session.foo does not exist, then there's something wrong with session-management on the client computer and we redirect with a "cookies are required" message.

All of this can be neatly handled in the boilerplate ("write it and fuhgeddaboudit") prologue of every-page, i.e. a cfincluded member.

(Nope, I don't have code to post.)

ilssac
Inspiring
June 16, 2009

Do all session variables fail or just certain one(s)?

Session state can be dissabled in the ColdFusion administrator, that would affect all variables on the entire site.


June 17, 2009

Hello Ian,

I am currently using only one session variable and CF Admin session settings are enabled.I am not sure why my session variable are not retaining any value. I have tried to output a session.USERID value and it shows me desired result but seems like it is not passing on value of Session.USERID to Authentication page.

Please if you can suggest me how to pass session values from one page to another, or if I have a mistake on sessioin variable syntax.   

ilssac
Inspiring
June 17, 2009

Add <cfdump var="#session#"> to your code.

Run your applicaiton several times.

Pay close attention to the session.cfid and session.cftoken OR session.jsessionid values (depends on how you have session state set up.)


If these values change with every request, your browser is not accepting and returning the cookies that ColdFusion tries to use to maintain session state.  Without these cookies, ColdFusion can not know that a new reqeust is part of a session started with an earlier request.

Message was edited by: Ian Skinner<br/> I see on your other thread that someone noticed that you have "setClientCookies=false" which means these cookies are not even being sent to the browser.  That is your problem.