Skip to main content
WolfShade
Legend
July 26, 2012
Answered

cfcookie question

  • July 26, 2012
  • 1 reply
  • 1329 views

Hello, everyone.

I know that one can access the cookie scope to get the value of a cookie.  Is there anything else that can be retrieved in the cookie scope?  Like the expires attribute?  Or is there another way to discover the expires value of a cookie?

Thanks,

^_^

    This topic has been closed for replies.
    Correct answer 12Robots

    Only the value can be retreived form the cookie scope. To get anything else you would need to reach into getPageContext() and get the request so you can fish out the actual cookie objects.

    <cfset cookies = getPageContext().getRequest().getHTTPRequest().getCookies() />

    <cfloop array="#cookies#" index="cookieIndex">

     

    <cfoutput>

                        Name: #cookieIndex.getName()#<br />

                        Value: #cookieIndex.getValue()#<br />

                        Expires: #cookieIndex.getMaxAge()#<br />

                        Domain: #cookieIndex.getDomain()#<br />

                        Path: #cookieIndex.getPath()#

      <br /><br />

    </cfoutput>

     

    </cfloop>

    1 reply

    12Robots
    12RobotsCorrect answer
    Participating Frequently
    July 26, 2012

    Only the value can be retreived form the cookie scope. To get anything else you would need to reach into getPageContext() and get the request so you can fish out the actual cookie objects.

    <cfset cookies = getPageContext().getRequest().getHTTPRequest().getCookies() />

    <cfloop array="#cookies#" index="cookieIndex">

     

    <cfoutput>

                        Name: #cookieIndex.getName()#<br />

                        Value: #cookieIndex.getValue()#<br />

                        Expires: #cookieIndex.getMaxAge()#<br />

                        Domain: #cookieIndex.getDomain()#<br />

                        Path: #cookieIndex.getPath()#

      <br /><br />

    </cfoutput>

     

    </cfloop>

    WolfShade
    WolfShadeAuthor
    Legend
    July 26, 2012

    Brilliant!  Thank you for showing me this.  I assume that the "expires" value is in milliseconds?

    ^_^

    12Robots
    Participating Frequently
    July 26, 2012

    Actually seconds.

    And interestingly, it is seconds after it is set inwhich it is supposed to expire. So really, I don't see anyway for you, from the server, to be able to tell when, specifically, it is supposed to expire. The brower knows when it was set, so it knows when to expire it, but I do not think that that data is sent back to the server.

    Jason