CGI::Session weird behavior

Hi,
If I uncomment line 14 nothing is displayed and each time the page is
refreshed ( 2 second interval) ruby creates a different file
/tmp/rubysess.*
But if I uncomment lines 17-23 it works, displaying the last access time
and only one session file is created.
Why is that? I don’t want to use cgi.out{} and stuff :frowning:

1 <%
2 require ‘cgi’
3 require ‘cgi/session’
4 require ‘cgi/session/pstore’
5 cgi = CGI.new(“html4”)
6
7 sess = CGI::Session.new( cgi, ‘database_manager’ =>
CGI::Session::PStore,
8 “session_key” => “a_test”,
9 “session_expires” => Time.now + 1 *
60,
10 “prefix” => “rubysess.”)
11 lastaccess = sess[“lastaccess”].to_s
12 sess[“lastaccess”] = Time.now
13
14 #print ‘’+lastaccess+’’
15
16 =begin
17 cgi.out{
18 cgi.html {
19 cgi.body(){
20 “Last access time: #{lastaccess}”
21 }
22 }
23 }
24 =end
25
26 sess.close
27
28 %>

On Aug 14, 9:55 am, Bruno S. [email protected] wrote:

3 require ‘cgi/session’
12 sess[“lastaccess”] = Time.now
23 }
24 =end
25
26 sess.close
27
28 %>

Posted viahttp://www.ruby-forum.com/.

If don’t want to use cgi.out, you’d need to at least send back some
http headers (at least Content-type) for anything to reach the user.
(also, I don’t know why you’re using cgi = CGI.new(“html4”) if you
don’t want the html helpers, but :\ )

pharrington wrote:

On Aug 14, 9:55�am, Bruno S. [email protected] wrote:

� 3 require ‘cgi/session’
�12 sess[“lastaccess”] = Time.now
�23 }
�24 =end
�25
�26 sess.close
�27
�28 %>

Posted viahttp://www.ruby-forum.com/.

If don’t want to use cgi.out, you’d need to at least send back some
http headers (at least Content-type) for anything to reach the user.
(also, I don’t know why you’re using cgi = CGI.new(“html4”) if you
don’t want the html helpers, but :\ )

The first thing you should output is:

print “Content-type: text/html\r\n\r\n”

or equivalently:

puts cgi.header

  1. Or you can also use cgi.out, which will automatically take care of
    the header information, like this:

require ‘cgi’

cgi = CGI.new

html =<<ENDOFHTML

Test

hello world

ENDOFHTML

cgi.out do
html
end