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

Hello, I'm experimenting by writing my own 'Shopping Cart'/'Catalog' using CGI and DBI, with MySQL.

Besides using cookies or hidden fields to store unique IDs, are there any other methods to keep the session? Or in other words, the server will still be able to recognise the user as being 'logged in'? Any sites or links about this to point out to me please?

I remember doing quite the same thing in school using JSP and Tomcat server. I'm just quite new at using Perl.

I hope you understand my English and what I'm asking about. Thank you!
  • Comment on Any other way to keep session besides cookies or hidden fields?

Replies are listed 'Best First'.
Re: Any other way to keep session besides cookies or hidden fields?
by ichimunki (Priest) on Jul 30, 2003 at 17:09 UTC
    The POD for CGI::Session has a good discussion of the various methods: cookies, query string, or hidden field. And of course, using the module will make your life easier at least as far as getting up and running with sessions.
Re: Any other way to keep session besides cookies or hidden fields?
by The Mad Hatter (Priest) on Jul 30, 2003 at 17:05 UTC
    One way or another, you're going to have to use cookies or a session id (either in the URL or in a hidden field) for reliable session management. Take a look at CGI::Session.
      You can also put the session key (as long as it is not predictable, e.g. an MD5 string) as the top directory in your URL:
         http://your.com/14681655ef653af/home.html
      
      The advantage of this approach is that if you make all of the links in your HTML relative to each other, you don't have to do any URL munging inside the HTML. Of course, you can forget about getting meaningful caching of proxy servers or browsers.

      The session key is easily obtainable with mod_perl or rewritten using mod_rewrite.

      Liz

Re: Any other way to keep session besides cookies or hidden fields?
by skyknight (Hermit) on Jul 30, 2003 at 17:23 UTC

    When you're calculating prices, make sure to pass the value of the items and/or the shopping cart total around as form variables, and tell me the domain name of the store, so I can come and buy out your entire inventory at a steep discount by editing the html form that you passed back to me. Also, when coming up with a server secret for cookie generation, make sure it's readily guessable so I can sniff cookies flying by in the ether, and generate my own authentication token for their account without even knowing their password. If you're feeling really magnanimous, don't bother with ssl, and just send passwords and and credit card numbers in the clear. ;-)

    Actually, you probably don't want to do any of these things, but you'd be surprised how often programmers of shopping carts fall into these traps.

Re: Any other way to keep session besides cookies or hidden fields?
by naChoZ (Curate) on Jul 30, 2003 at 18:19 UTC