dominoExperts.com - Powered by Domino 8.5.2 Domino Accelerator Pack
- DAP know which URLs slow down your site. Do you?
Lotus Triple Search DominoExperts + Blogs + R8 forum
dominoExperts.com -> General Domino Talk

 Some cookie handling examples


Tomas NielsenPost date: 2007-03-15 21:12

I have been asked how I handle cookies and here are some examples. Cookies can be handled in a number of ways and I guess I have tried most of them. These examples are on the server side. Cookies can also be set from JavaScript in the client.

Setting cookies from a LS OpenAgent:

Code:
Sub Initialize
   Print "Status: 200"
   Print |Set-Cookie: user=Tomas Nielsen; expires=Wed, 9 Dec 2009 21:00:02 GMT; path=/|
   Print "Content-type:text/html; charset=UTF-8" ' Format a nice header telling the content type.
   Print |Cache-control: no-cache, no-store, must-revalidate| ' Not a good idea to cache this.
   Print ""
   Print |<html><head>|
   Print |<SCRIPT Language="JavaScript">|
   Print |<!--|
   Print |document.location.href = "/";| ' Send the user to the start page
   Print |//-->|
   Print |</script>|
   Print |</head></html>|
End Sub

You would probably want to change the content part of the cookie but you get the idea. Leave out the expires part if you want the cookie to die when the user closes the browser.
The "path" part is best left at pointing at the root. In domino situations you will most probably get into trouble if you set this one to point to a database. It is really hard to try to debug why your cookie is not available if you set the path wrong.


Here is an example of how to read out the cookie once the cookie is set:

Code:
Sub Initialize
 Dim session As New notessession
 Dim doc As notesDocument

 Set doc = session.documentContext
 dim user as variant
 user = Evaluate(|@Middle(HTTP_Cookie; "user="; ";");|, doc)
 print "Welcome back " + user(0) + "!"














End Sub



RSS feed
Subscribe to Forum

Share this page

Top posters
Tomas Nielsen212
Joacim Boive27
Fredrik Stöckel27
Danne14
Niklas Waller13
Kenneth Haggman11
Bryan Kuhn10
Daniel Lehtihet9
Jonas Israelsson8
dm997