You can implement sessions on your Web site using Ruby
#! /ruby/bin/ruby
require 'cgi'
require 'cgi/session'
cgi = CGI.new("html3")
sessionKey = "yourKey"
sessionPrefix = "session."
session = CGI::Session.new(cgi, "session_key" => sessionKey,
"prefix" => sessionPrefix)
$lastAccess = session["lastAccess"]
$visits = session["visits"]
if $visits == nil
$visits = 1
else
$visits = $visits.to_i + 1
end
session["visits"] = $visits
session["lastAccess"] = "#{Time.now}"
cgi.out() do
cgi.html do
begin
if $visits == 1
"first visit!" +
else
"This is visit number #{$visits} this session." +
"Your last access was at #{$lastAccess}<p>" +
"The current time is #{Time.now}" +
end
end
end
end
Related examples in the same category