CGI::Session just don't work

B

Bruno Sousa

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?
 
7

7stud --

Bruno said:
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
 
B

Brian Candler

7stud said:
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.
 
7

7stud --

Brian said:
7stud said:
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. :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

CGI::Session weird behavior 2
Retrieving session data from a cookie 0
CGI::Session Question 0
CGI::Session not sending cookie 0
Session in Eruby 0
Session Eruby.noheader problem 0
Ruby CGI questions 3
CGI help 18

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top