require 'cgi'
require 'cgi/session'
cgi = CGI.new("html3")
sess = CGI::Session.new(cgi,
"session_key" => "rubyweb",
"prefix" => "websession."
)
if sess['lastaccess']
msg = "You were last here #{sess['lastaccess']}."
else
msg = "you haven't been here for a while"
end
count = (sess["accesscount"] || 0).to_i
count += 1
msg << "Number of visits: #{count}"
sess["accesscount"] = count
sess["lastaccess"] = Time.now.to_s
sess.close
cgi.out {
cgi.html {
cgi.body {
msg
}
}
}