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

cfcookie question

LEGEND ,
Jul 26, 2012 Jul 26, 2012

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,

^_^

1.3K
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

correct answers 1 Correct answer

Advocate , Jul 26, 2012 Jul 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 />

  

...
Translate
Advocate ,
Jul 26, 2012 Jul 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>

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
LEGEND ,
Jul 26, 2012 Jul 26, 2012

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

^_^

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
Advocate ,
Jul 26, 2012 Jul 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

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
LEGEND ,
Jul 26, 2012 Jul 26, 2012

You should be able to (after this point) be able to use some sort of dateParse() function to get the date/time of expiration.

.. I think.

^_^

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
Advocate ,
Jul 26, 2012 Jul 26, 2012

No, you can't Because it is not a date/time, it is a timespan. The translation is a periodu of time. For example the valeu might be: 345600.  That translates to 4 days, 0 hours, 0 minutes, 0 seconds. It will not translated to August 2nf 2012 at 14:00 CST. So if I set that cookie now and check the MaxAge property it will say 345600, if I check it tomorrow at 6:00 AM it will say 345600. If I check it 3 days from now at 4:00 PM it will say 345600.  If I don't know when that cookie was set, I won't know when it will expire.

jason

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
LEGEND ,
Jul 26, 2012 Jul 26, 2012
LATEST

Ah, okay.. I see what you're saying, now.  Bummer.    Thank you for your help!

^_^

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