# CGI Sessions

**URL:** <https://www.ruby-forum.com/t/cgi-sessions/158888>\
**Category:** Rails\
**Created:** [January 29, 2009, 3:31am UTC](https://www.ruby-forum.com/t/cgi-sessions/158888 "2009-01-29T03:31:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [January 29, 2009, 3:31am UTC](https://www.ruby-forum.com/t/cgi-sessions/158888/1 "2009-01-29T03:31:25Z")

</div>

I have several Rails sites running that use sessions and they all post  
cookies properly and otherwise work flawlessly. I now have need of  
implementing a more raw approach to sessions using CGI::Sessions.

The Pickaxe book gives an example of how to do it (which I will append  
to this message) after which they make the following statement:

This will send a cookie to the user named ``rubyweb’’ with a value of  
9650. It will also create a disk file in $TMP/web-session.9650 with  
the key, value pairs for CustID and Part.

Upon trying the example, I first notice that the disk file is not  
named ‘session.9650’. That’s not a big deal. However, of more  
importance is the fact that it fails to plant a cookie in my browser.  
Apparently, this failure prevents it from knowing that a session has  
been established; so, it opens a new session with each access.

Because my Rails installations do sessions so well, I conclude that  
the Rails community must know something about getting this to work  
that I don’t. I’m hopeful that someone here can point out the error  
of my ways and I hope that my post will not be considered too far off  
topic. If anyone can help me, I would deeply appreciate it. Thanks.

```
   ... doug

```

P.S. – Pickaxe Example:

\<% require “cgi”  
require “cgi/session”  
cgi = CGI.new(“html3”)  
sess = CGI::Session.new( cgi, “session\_key” =\> “rubyweb”,  
“session\_id” =\> “9650”,  
“new\_session” =\> true,  
“prefix” =\> “web-session.”)  
sess[“CustID”] = 123  
sess[“Part”] = “ABC” %\>
