Problem with session under cgi file

When i set a value in session after changing page session doesn't
remember the value.
I have an example.
Page: http://darksky.pl/test/index.cgi
Source: http://darksky.pl/test/index.txt
Don't ask why I have to make it with cgi ;/

···

--
Posted via http://www.ruby-forum.com/.

you need to make sure you flush and close it.

-a

···

On Sun, 25 Feb 2007, Dsa Dang wrote:

When i set a value in session after changing page session doesn't
remember the value.
I have an example.
Page: http://darksky.pl/test/index.cgi
Source: http://darksky.pl/test/index.txt
Don't ask why I have to make it with cgi ;/

--
be kind whenever possible... it is always possible.
- the dalai lama

you need to make sure you flush and close it.

I've added sess.close at the end but it still doesn't work :confused:

···

--
Posted via http://www.ruby-forum.com/\.

are you setting the expiration?

   cgi = CGI.new

   session = CGI::Session.new(cgi, "session_expires" => Time.at(2**31-1))
   at_exit{ session.update; session.close }

-a

···

On Sun, 25 Feb 2007, Dsa Dang wrote:

you need to make sure you flush and close it.

I've added sess.close at the end but it still doesn't work :confused:

--
be kind whenever possible... it is always possible.
- the dalai lama

Good suggestions, but both should be unnecessary. CGI::Session uses a
finalizer to ensure the session is closed and all the builtin session stores
update on close. No expires means the cookie lives for the duration of the
browser session.

Your source suggested you may be sending a malformed HTTP response. Inspect
the request and response in Firebug to see: look for the Set-Cookie header
in the response and the Cookie header in subsequent requests.

jeremy

···

On 2/24/07, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:

On Sun, 25 Feb 2007, Dsa Dang wrote:

>> you need to make sure you flush and close it.
>
> I've added sess.close at the end but it still doesn't work :confused:
>

are you setting the expiration?

   cgi = CGI.new

   session = CGI::Session.new(cgi, "session_expires" => Time.at(2**31-1))
   at_exit{ session.update; session.close }

yeah i know - i had issues with this just last week though - i'll try to
reproduce...

-a

···

On Sun, 25 Feb 2007, Jeremy Kemper wrote:

are you setting the expiration?

   cgi = CGI.new

   session = CGI::Session.new(cgi, "session_expires" => Time.at(2**31-1))
   at_exit{ session.update; session.close }

Good suggestions, but both should be unnecessary. CGI::Session uses a
finalizer to ensure the session is closed and all the builtin session stores
update on close. No expires means the cookie lives for the duration of the
browser session.

--
be kind whenever possible... it is always possible.
- the dalai lama

So.. my friend have found what was wrong. It's all about session id.
Here it must be send manually. I'll leave the source here as it may be
deleted from the server soon (first old source, then correct and
working).

···

--------------
old:
#!/usr/bin/ruby

require 'cgi'
require 'cgi/session'
require 'cgi/session/pstore'

def mojaSesja(cgi)
  return CGI::Session.new(cgi,
      #'database_manager' => CGI::Session::PStore, # use PStore
      'session_key' => 'rek_key', # custom session key
      'session_expires' => Time.now + 30 * 60, # 30 minute timeout
      'prefix' => 'rek_') # PStore option
end

cgi = CGI.new("html4")
sess = mojaSesja(cgi)

puts "Content-type: text/html\n\n"
puts "<a href='index.cgi?z=a'>a</a><br />"
puts "<a href='index.cgi?z=b'>b</a><br />"

if cgi['z'] == 'a'
  sess['z'] = cgi['z']
  sess.update
end

puts sess['z']

--------------
new (ok):

#!/usr/bin/ruby

require 'cgi'
require 'cgi/session'
require 'cgi/session/pstore'

def mojaSesja(cgi)
  CGI::Session.new(cgi,
        #'database_manager' => CGI::Session::PStore, # use PStore
      'session_key' => 'session_id', # custom session key
      'session_expires' => Time.now + 30 * 60, # 30 minute timeout
      'prefix' => 'rek_') # PStore option
end

cgi = CGI.new("html4")
sess = mojaSesja(cgi)

puts "Content-type: text/html\n\n"
print "<a href='index.cgi?z=a&session_id=",sess.session_id,"'>a</a><br
/>"
print "<a href='index.cgi?z=b&session_id=",sess.session_id,"'>b</a><br
/>"

if cgi['z'] == 'a'
  sess['z'] = cgi['z']
end

puts sess['z']

sess.close

--
Posted via http://www.ruby-forum.com/.