If you're trying to maintain state in httpd sessions, you have a few options. I'm taking this from O'Reilley's CGI Programming with Perl, second edition.
  1. Query strings and extra path information.

    I don't care for this method, as one is forced to try to reliably parse all links in documents.

  2. Cookies.

    This is the most reliable. It's easy to use and doesn't matter if the user leaves your site and returns later. However, if your Web site is dedicated to the premise that "BATF employees are bunch of jack-booted thugs", many of your users are probably concerned about privacy and have cookies disabled.

  3. Hidden fields.

    I like this method, but it only works across a series of form submissions. If the user leaves your site and returns later, state information is probably lost.

Regardless of the method used, you should probably be employing some form of generating a digest or random key for the session id. I prefer the idea of generating a digest with MD5 or SHA1, since many people who try to generate a random key will do so on their own and not generate a key random enough. Unless you're a cryptography wiz (and I'm not), trying to "roll your own" is bad if you are really concerned about security.

Re: MD5. According to this node, if you use MD5, you should run it twice to prevent someone from duplicating your key with different information. In fact, the aforementioned book points out that theoretical vulnerabilities have been discovered in the MD5 algorithm. As a result, I recommend Digest::SHA1. It does not have these vulnerabilities. Even if it is slower than MD5, it's probably faster than running MD5 twice, though I have not benchmarked it.

If you're interesting in using user information to generate a digest, the following algorithm is listed:

use Digest::MD5; my $md5 = new Digest::MD5; my $remote = $ENV{REMOTE_ADDR} . $ENV{REMOTE_PORT}; my $id = $md5->md5_base64( time, $$, $remote ); $id =~ tr|+/=|-_.|; # Make non-word characters URL-friendly
Further, here's a quote from the book regarding this method:
This does a good job of generating a unique key for each request. However, it is not intended to create keys that cannot be cracked. If you are generating sessions identifiers that provide access to sensitive data, then you should use a more sensitive method to generate an identifier.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just go the the link and check out our stats.


In reply to (Ovid) Re: sessions: MD5 versus random strings by Ovid
in thread sessions: MD5 versus random strings by markjugg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.