From: Frank Fejes Date: 2003-03-07T01:33:32+09:00 Subject: Re: cookies in eruby mod_ruby On Thu, 06 Mar 2003 13:44:30 +0900, Daniel Bretoi wrote: > Can someone explain how to set/delete cookies using mod_ruby (eruby)? > Or even better, point me to some documentation which will show me how. > I've spent hours trying to find docs and had to cave in. Personally, I don't quite like the CGI#out style of doing things so I set the headers myself then output the html my own way. It's just as easy and I feel like I'm in a bit more control. Here is a sample eruby program to set a couple cookies: <% require 'cgi' # get an expiration date string for a year from now ed = CGI.rfc1123_date(Time.now + (60 * 60 * 24 * 365)) r = Apache.request r.content_type = 'text/html' r.headers_out.add('Set-Cookie', 'name=frank; path=/; expires=%s' % ed) r.headers_out.add('Set-Cookie', 'language=eruby; path=/; expires=%s' % ed) r.send_http_header %> Here are the headers that came in:
<% r.headers_in.each { |h| p h } %>
Here are the headers we added and sent out:
<% r.headers_out.each { |h| p h } %>
Note that to use this with mod_ruby or plain cgi you'd just have to remove the <% and %> markers and then add code to display the html that eruby is displaying for you. Let me know if you have any questions. --frank PS: By the way, since you asked, to delete a cookie you'd just set another cookie with the same variable and path but with an expiration date in the past.