Session in Eruby

B

Bruno Sousa

I'm trying to make a simple use of CGI::Session.

For example, if page1.rhtml is like this:
1 <%
2 require 'cgi'
3 require 'cgi/session'
4 require 'cgi/session/pstore' # provides CGI::Session::pStore
5
6 cgi = CGI.new("html4")
7
8 session = CGI::Session.new(cgi,
9 'database_manager' => CGI::Session::pStore, # use PStore
10 'session_key' => '_rb_sess_id', # custom session
key
11 'session_expires' => Time.now + 30 * 60, # 30 minute
timeout
12 'prefix' => 'pstore_sid_') # PStore option
13 if cgi.has_key?('user_name') and cgi['user_name'] != ''
14 # coerce to String: cgi[] returns the
15 # string-like CGI::QueryExtension::Value
16 session['user_name'] = cgi['user_name'].to_s
17 elsif !session['user_name']
18 session['user_name'] = "guest"
19 end
20 session.close
21
22 %>


How should page2.rhtml be like if I want to recover
session['user_name']?
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top