# A simple implementation of Netscape Cookies. # # What are Cookies? # # They are State ID's that a kind client (e.g., Netscape) # will pass back to you so you can track "sessions," instead # of just individual "hits" to your site. The official cookie # spec is at: # # http://home.netscape.com/newsref/std/cookie_spec.html # # What does this code do for me? # # It shows how to set the cookie initially, and how to # look to see if it's been passed in. # # Where do I get a value for a cookie? # # There are lots of ways to do this, the simplest being just keep # a global counter. That counter can be in the database or a # global variable. To set a global variable, use ns_eval; for # example, use "ns_eval incr counter" to increment the counter. # # If you are storing your state information in an Illustra # database, the oid makes a good cookie. # # Where do I store the actual state information? # # You can store it any number of places including the database # or Tcl associative array. # # What's the bad news? # # The only real bad news is that Netscape is the only browser # we know of that supports cookies. # # Enjoy! # # Alex Wells (wells@alexandria.sdc.ucsb.edu), Alexandria Digital Library # Doug McKee (doug@navisoft.com), NaviSoft # # # Script Info: # # Distributed through Cookie Central. # http://www.cookiecentral.com. # ##################################################################### # proc AddHTTPCookieHeader {conn cookie} { # This function will add a cookie to the header that will be returned # by the NaviServer. When a client makes a request to the same host # and location contained underneath the specified path (in this case # "/"), that same cookie is passed back to the server in the headers # of the request. set headerSet [ns_conn outputheaders $conn] ns_set put $headerSet "Set-Cookie" "SID=$cookie; path=/" } # To access the cookie from a request, just add the following line to # your code: # # set cookie [ns_set get [ns_conn headers $conn] Cookie] #