From: GOTO Kentaro Date: 2002-02-22T03:32:43+09:00 Subject: Re: dang it, CGI::Session is broken again In message "Re: dang it, CGI::Session is broken again" on Fri, 22 Feb 2002 00:18:46 +0900, dmcnulty@mindspring.com (Dan McNulty) writes: > Doesn't CGI::Session use cookies to store the data on the client side? > I am pretty sure it does, but then why isn't this part happening? Your script does NOT send HTTP header, where cookies shoud be put. Try: sess = CGI::Session.new(cgi, "session_key" => "a_test", "prefix" => "rubysess.") print cgi.header("text/plain") ##### INSERT THIS LINE ##### if sess["junk"]==nil print "A new session ", "junk is ", sess["junk"], "\n" sess["junk"]=123 .... If you use that with mod_ruby, this may be not good. A simple way is use of CGI#out that gives common interface to both of mod_ruby and non mod_ruby. The following lists a sample: #!/usr/local/bin/ruby require "cgi" require "cgi/session" cgi = CGI.new sess = CGI::Session.new(cgi, "session_key" => "a_test", "prefix" => "rubysess.") body = "" # used as output buffer if sess["junk"]==nil body << "A new session junk is #{sess["junk"]}\n" sess["junk"]=123 body << "A new session junk is now #{sess["junk"]}\n" sess.close else body << "An existing session junk is #{sess["junk"]}\n" sess["junk"]=sess["junk"].to_i + 1 body << "An existing session junk is now #{sess["junk"]}\n" sess.close end cgi.out("text/plain"){body} Hope this helps, -- Gotoken