leocharre has asked for the wisdom of the Perl Monks concerning the following question:

I'm kind of scared to get shot at for asking this but uhm...

I notice there's not a lot in the way of CGI::Sessions - note the plural.
If I have multiple users logged in and I want to see data on them.. by looking in the files in /tmp/cgisess_*

Obviously this implies using file, storable method to use sessions.

Replies are listed 'Best First'.
Re: open sessions management
by jdtoronto (Prior) on Sep 20, 2006 at 15:27 UTC
    Shot? Why? (laughs!)

    I use CGI::Session stand-alone in one application and through CGI::Application in many others. Yes, I use a database table. Dont forget you can store information of yourown in the session. In a shopping cart I store the complete transient cart in the session until the user goes to the checkout.

    CGI::Session with alittle bit of code will manage the session, what else you need to do witht he session and its data is up to you. Some of the extras you are suggesting are esilly handled with various frameworks - if they need to be addressed at all. Remote user names, IP's and such are in the CGI query, or in the ENV variables for the instance. Current session will usually come back to you in a cookie and is handled by CGI::Session so you don't really need to ask for it, just use it!

    Like lots of things in Perl, it happens by magic :) Have you read the tutorial that comes withthe module yet?

    jdtoronto

      I'm sorry. I was not clear... Yes I've read the tutorials, doc, etc.. Wise to mention.
      I love CGI::Session.. it works great. We just like to drop in every now and then and get a quick look at who's there and what they are doing.

      I hacked together some code to scan the current cgi sessions and spit out a summary.. and let someone kill sessions etc at will. ban ips, etc. I'm coming back to it.. I thought it would be a hack just for temporaty use.. but as it turns out.. it's wanted. So.. I wanted to clean it up- and I can't seem to find a module that handles a quick interface to all sessions open etc ... using storable, not the other ways.

      I am tempted to write-hack together a little module to provide methods to work with multiple cgi sessions that are opened.

Re: open sessions management
by perrin (Chancellor) on Sep 20, 2006 at 15:44 UTC
    Are you asking why some session modules use Storable to serialize data? Data has to be serialized somehow, and Storable is faster and more compact than any of the other methods. That's all there is to it. If you want to read the data in a session, just load it with Storable. It's not encrypted in any way.

      What I am wondering about is why there doesn't seem to be available code for dealing with existing sessions.. for managing multiple existing open CGI::Sessions. That is at least in regards to when it's saved as a cgi session file. I have seen this asked before, but I haven't seen it answered.

        Part of the problem leoncharre is that everybody uses CGI::Session differently. As perrin said, you can just use Storable and look at the file, but then you need to know what you are looking for! And you need to know what you put in there. Storable is fast and full of goodness, but it doesn't work for every situation.

        We have one instance where we use a single session database shared between three Web-apps. So for that we need to use the database - typically MySQL. The real fun part is that we can, of course, have the different apps on different machines that way. But I think the reason you haven't seen any modular code is because in reality very few people need to peer into the session data for any reason. If you do it is likely that your requirements will be more than minimal and you would need to craft it yourself anyway.

        jdtoronto

        For "dealing with existing sessions"? What does that mean? Are you asking why no one has written a utility to run Storable on the files? Probably either no one needed it, or it was so easy that they figured no one else would want the code. Have you tried it? If you're stuck, I'm sure we could help.