Skip to main content
BreakawayPaul
Inspiring
May 27, 2014
Answered

Checking session variables

  • May 27, 2014
  • 1 reply
  • 1052 views

I have an external login service that I'm using to authenticate users.  After logging in, I get an XML file from which I can pull things like user ID and rights.

The login page redirects to an index page in another folder (which is protected by the authentication service) and on that page, I have a <cfif> statement that looks at rights.

The rights returned are "J" (for judge) and "A" (for admin), which I'm setting as the session variable: session.rights

If I do this:

<cfif session.rights eq "A">

admin section

<cfelseif session.rights eq "J">

judge section

<cfelse>

redirect to the login page

</cfif>

The else is what triggers.  If I cfoutput #session.rights# I get J, but for some reason, J does not equal J.  I've tried trimming it and everything, to no avail.

Any ideas?

    This topic has been closed for replies.
    Correct answer duncancumming

    Yeah, I've trimmed everything everywhere, to no avail.

    Here's the dump result:

    struct
    emailaddr [empty string]
    newitem 1
    rights
    xml element
    XmlNameTPEA_USER_TYPE
    XmlNsPrefix
    XmlNsURI
    XmlTextJ
    XmlComment
    XmlAttributes
    struct [empty]
    XmlChildren 
    sessionid f0306d37e90bce8a818d7d7843e36516f1e7
    tpeauser <?xml version="1.0" encoding="UTF-8"?> <NAME_FIRST>Dave</NAME_FIRST> <?xml version="1.0" encoding="UTF-8"?> <NAME_LAST>Johnson</NAME_LAST>
    trackingno 0
    upacsid [empty string]
    upacsserver [empty string]
    urltoken  CFID=26143&CFTOKEN=6071485a4b7e13-F5282421-A324-841F-59919221D2C51604&jsessionid=f0306d37e90bce8a818d7d7843e36516f1e7 
    userid
    xml element
    XmlNameUSER_ID
    XmlNsPrefix
    XmlNsURI
    XmlText25481
    XmlComment
    XmlAttributes
    struct [empty]
    XmlChildren 

    there's your problem.  Session.rights does not = "J", it's a block of XML.  You'd need to at least say

    <cfelseif session.rights.XmlText eq "J"> 

    1 reply

    Participating Frequently
    May 28, 2014

    could it be possible that session.rights has some whitespace around it e.g. "  J" or "J  " ?  When you output it you'll only see 'J' but session.rights EQ "J" == false.  You may just need to trim it:

    <cfelseif trim(session.rights) eq "J">

    Legend
    May 28, 2014

    Please do a <CFDUMP VAR="#session#"> and paste the results here. Try an IS as opposed to EQ as well, to see if that helps.

    BreakawayPaul
    Inspiring
    May 28, 2014

    Yeah, I've trimmed everything everywhere, to no avail.

    Here's the dump result:

    struct
    emailaddr [empty string]
    newitem 1
    rights
    xml element
    XmlNameTPEA_USER_TYPE
    XmlNsPrefix
    XmlNsURI
    XmlTextJ
    XmlComment
    XmlAttributes
    struct [empty]
    XmlChildren 
    sessionid f0306d37e90bce8a818d7d7843e36516f1e7
    tpeauser <?xml version="1.0" encoding="UTF-8"?> <NAME_FIRST>Dave</NAME_FIRST> <?xml version="1.0" encoding="UTF-8"?> <NAME_LAST>Johnson</NAME_LAST>
    trackingno 0
    upacsid [empty string]
    upacsserver [empty string]
    urltoken  CFID=26143&CFTOKEN=6071485a4b7e13-F5282421-A324-841F-59919221D2C51604&jsessionid=f0306d37e90bce8a818d7d7843e36516f1e7 
    userid
    xml element
    XmlNameUSER_ID
    XmlNsPrefix
    XmlNsURI
    XmlText25481
    XmlComment
    XmlAttributes
    struct [empty]
    XmlChildren