CGI::Session just don't work

I got this file to a apache/mod-ruby server and nothing is being set to
“lastaccess”

test.rhtml:
<%
require ‘cgi’
require ‘cgi/session’
cgi = CGI.new(“html4”)

sess = CGI::Session.new( cgi, “session_key” => “a_test”,
“prefix” => “rubysess.”)
lastaccess = sess[“lastaccess”].to_s
sess[“lastaccess”] = Time.now
if cgi[‘bgcolor’][0] =~ /[a-z]/
sess[“bgcolor”] = cgi[‘bgcolor’]
end

cgi.out{
cgi.html {
cgi.body (“bgcolor” => sess[“bgcolor”]){
“The background of this page” +
“changes based on the ‘bgcolor’” +
“each user has in session.” +
“Last access time: #{lastaccess}”
}
}
}
%>

What can be happenning?

Bruno S. wrote:

I got this file to a apache/mod-ruby server and nothing is being set to
“lastaccess”

test.rhtml:
<%
require ‘cgi’
require ‘cgi/session’
cgi = CGI.new(“html4”)

sess = CGI::Session.new( cgi, “session_key” => “a_test”,
“prefix” => “rubysess.”)
lastaccess = sess[“lastaccess”].to_s
sess[“lastaccess”] = Time.now
if cgi[‘bgcolor’][0] =~ /[a-z]/
sess[“bgcolor”] = cgi[‘bgcolor’]
end

cgi.out{
cgi.html {
cgi.body (“bgcolor” => sess[“bgcolor”]){
“The background of this page” +
“changes based on the ‘bgcolor’” +
“each user has in session.” +
“Last access time: #{lastaccess}”
}
}
}
%>

What can be happenning?

A first access cannot have a lastaccess?

Also:

result = “hello”[0]
puts result

if result =~ /h/
puts ‘yes’
else
puts ‘no’
end

–output:–
104
no

7stud – wrote:

Also:

result = “hello”[0]
puts result

No, the OP is correct. In the CGI library, cgi[‘foo’] is an array. This
is to allow for usage such as /myprogram.cgi?foo=123&foo=456

However, the next line should probably say

sess["bgcolor"] = cgi['bgcolor'][0]

or else later on,

cgi.body ("bgcolor" => sess["bgcolor"][0]){

But as to the problem with CGI::Session: I’m afraid it’s a very long
time since I bothered with rhtml or CGI, and I’m not sure that mod_ruby
has had much care and attention.

These days I think you’ll find that most people write Rack applications
(Rails and Sinatra are both layers on top of Rack), so Rack’s
session-handling is much more widely tested.

Deploying a Rails or Sinatra application under Apache is very easily
done with Phusion Passenger.

Brian C. wrote:

7stud – wrote:

Also:

result = “hello”[0]
puts result

No, the OP is correct. In the CGI library, cgi[‘foo’] is an array. This
is to allow for usage such as /myprogram.cgi?foo=123&foo=456

I’m not seeing that. It’s my understanding that cgi handles multiple,
indentical names with cgi.params. For instance, given your url
cgi.params[“foo”] would return an array. However, cgi[“foo”] would
return the string “123”

However, the next line should probably say

sess["bgcolor"] = cgi['bgcolor'][0]

or else later on,

cgi.body ("bgcolor" => sess["bgcolor"][0]){

But as to the problem with CGI::Session: I’m afraid it’s a very long
time since I bothered with rhtml or CGI, and I’m not sure that mod_ruby
has had much care and attention.

I’m not even sure what this question has to do with mod_ruby. :frowning: