The following script is a simple page counter that works well for me running
as an rhtml file on mod_ruby:
<%
require ‘cgi/session’
cgi = CGI.new(‘html4’)
session = CGI::Session.new(cgi)
session[‘count’] ||= 0
session[‘count’] = session[‘count’].to_i + 1
content must be output in this way in order for headers to be written:
cgi.out { "count: " + session[‘count’] }
session.close
%>
However, if I replace the line “cgi.out …” with "puts session[‘count’]"
the script fails incrediment indicating that a new session is being created
every time. I would assume this is because the right headers (cookies,
etc…) are not written out in the response. If you use CGI::Session are you
forced to use cgi.out rather than your own output method?
···
–
John Long
www.wiseheartdesign.com