how to set a expire time for a cookie?

Primary tabs

Atelier, Caché

I try to set a cookie with expire time like this:  %response.SetCookie("XXXXX",%session.SessionId,%session.AppTimeout,"","",0,0)  but when i return to the browser it shows that the cookie's("XXXXX") expire time is "session". How can i to set a expire time? Can someone help me? thxsmiley

  • 0
  • 0
  • 37
  • 1
  • 2

Answers

Third parameter is expire:

d %response.SetCookie("XXXXX",%session.SessionId,"expirationdate")

For example:

d %response.SetCookie("XXXXX",%session.SessionId,"Wed, 31 Oct 2020 00:00:00 GMT")

you use %session.AppTimeout which has a default of 900 (sec).

but SetCookie asks for a Time !
method SetCookie(name As %String, value As %String, expires As %String = "", path As %String = "", domain As %String = "", secure As %Boolean = 0, httpOnlyFlag As %Boolean = 0) 

I see from https://stackoverflow.com/questions/13154552/javascript-set-cookie-with-expire-time
what string this might be.

'Mon, 18 Nov 2019 08:50:17 GMT';

My assumption - your 900 was just not recognized and the default (=session) was set