Stephen Legrand - 2003-04-15

I'm a newbie to web development and ruby-tmpl. Ruby-tmpl seems to be a good solution since I will want to send down javascript and/or svg to the client and templates are the way to go. However, right now I'm trying to manage sessions via uri but each time I refresh, I get a brand new session.  Obviously I'm doing something stupid. Below is my code and it's templated.

#!/usr/local/bin/ruby
require 'cgi'
require 'cgi/session'
require 'ruby-tmpl'

the code...

cgi=CGI.new('html4')
sess=CGI::Session.new( cgi, 'session_key'=>'id', 'prefix'=>'rubysess' )
lastaccess = sess['lastaccess']
sess['lastaccess']=Time.now.to_i
sid = sess.session_id
tmpl = Template.new
tmpl.file='testsession.tmpl'
tmpl.path='./tmpl'
tmpl.use_mod_ruby = false
tmpl.munge_output = false
info1="Last access time: #{lastaccess} "
info2=" Session id (sid)= #{sid} "
tmpl.set('info1',info1)
tmpl.set('info2',info2)
tmpl.session_param='id'
tmpl.session = sid
tmpl.print

and the template...

Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test Session</title>
</head>
<body bgcolor="#ccddff">
<H1> Test Session.</H1>
<BR><BR><BR>
<?tmpl.var name="info1" ?>
<BR><BR>
<?tmpl.var name="info2" ?>
<BR>
</body>
</html>