Server side cookies in Domino
Session Cookie
This cookie expires when the browser is closed. Be careful: the value has to be escaped. I tried @URLEncode, but this didn't work properly. In the samples, only the space is escaped. In the cookie, I also set the path to "/", which makes it valid for the entire site and not only for the current subfolder.
rem "setting a session cookie";
cName:="name";
cValue:="Lotus Notes Domino";
@If(@BrowserInfo("Cookies");""; @Return("Error: cookies not enabled."));
result:=cName+"="+@ReplaceSubstring(cValue; " "; "%20")+"; path=/;";
@SetHTTPHeader("Set-Cookie"; result);
Persistent Cookie
This cookie stays when the browser is closed. Setting the expiration date to 10 years from now should be more than enough.
rem "setting a persistent cookie";
cName:="name";
cValue:="Lotus Notes Domino";
@If(@BrowserInfo("Cookies");""; @Return("Error: cookies not enabled."));
result:=cName+"="+@ReplaceSubstring(cValue; " "; "%20")+"; path=/;";
a:=@Date(@Year(@Now)+10; 12; 31);
wd:=@Word("Sun Mon Tue Wed Thu Fri Sat"; " "; @Weekday(a));
mm:=@Word("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"; " "; @Month(a));
expires:=" expires="+wd+", "+@Text(@Day(a))+"-"+mm+"-"+@Text(@Year(a))
+" 23:59:59 GMT";
@SetHTTPHeader("Set-Cookie"; result+expires);
Deleting a Cookie
Tho delete a cookie, you have to set its value to "" and its expiration date in the past.
rem "deleting cookie";
cName:="name";
a:=@Date(@Year(@Now)-1; 1; 1);
wd:=@Word("Sun Mon Tue Wed Thu Fri Sat"; " "; @Weekday(a));
mm:=@Word("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"; " "; @Month(a));
expires:=" expires="+wd+", "+@Text(@Day(a))+"-"+mm+"-"+@Text(@Year(a))
+" 23:59:59 GMT";
@SetHTTPHeader("Set-Cookie"; cName=";"+expires);Star rating
90%
Comments
To add a comment, log in or register as new user. It's free and safe.