Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Web Cookies via Perl

by tradez (Pilgrim)
on Jun 05, 2002 at 16:30 UTC ( #171895=perlquestion: print w/replies, xml ) Need Help??
tradez has asked for the wisdom of the Perl Monks concerning the following question:

My Fellow Monks, I come to you for guidance after spending the last weeks of my time here in earth redoing a website to make it "cross browser compliant". I am sure that someday we will find a standard for all browsers to follow, W3C . I now wish to utilize cookies to customize the page to a users liking. I have chosen the CGI::Cookie medium and before I get to far into it, I thought I would petition the monks for horror stories they have had with cookies. Is there a better way other then cookies to store per user variables, is there a better module. Have tried Apache's cookie module, but had issues. Any help will be much appreciated.

"Never underestimate the predicability of stupidity"
- Bullet Tooth Tony, Snatch (2001)

Replies are listed 'Best First'.
Re: Web Cookies via Perl
by 914 (Pilgrim) on Jun 05, 2002 at 16:36 UTC
    hey there tradez....

    i've done a fair bit of stuff with cookies, and certainly the CGI::Cookie module can (will!) make your life a lot easier.

    the only real bit of wisdom i've got for you is to be careful with the *order* in which you set cookies, as related to the rest of the http_header. The WebTV browser is particularly finicky, once when i had to insert some extra cookies 'manually' (the module was automatically escaping some of the characters, and we didn't want that) all of the folks with WebTV browsers were shut out.

    Unforutnately, the "emulator" supplied by WebTV did NOT handle/parse the cookies in the same way that the real client did, and so did not reveal this problem.

    i'm sure there are plenty of other funky clients out there to make things fun, but that's the one that's given me the most trouble in relation to cookies.

    have fun!

Re: Web Cookies via Perl
by Hero Zzyzzx (Curate) on Jun 05, 2002 at 20:25 UTC

    Be explicit with your cookies, too- Set a path that will work for you and a domain, and don't expect that cookies set at "" are going to be available at "," this is dependent on the settings of a browser.

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

Re: Web Cookies via Perl
by Ryszard (Priest) on Jun 05, 2002 at 23:03 UTC
    Really, the only thing you want to store in a cookie is a sess_id. From the sess_id you can get any information you like that is stored server side.

    I've only ever used because it is a tried and tested method, and it is *very* easy to use.

    Check out this node for some info and other links on maintaining state with HTTP.

Re: Web Cookies via Perl
by George_Sherston (Vicar) on Jun 05, 2002 at 19:54 UTC
    My only thought, which you have probably already had, is to store minimum info in the cookie. Just a unique identifier, which you can then use to call user info from the server, where you control how it's used and interpreted. So the only cookie-business is one write and then one read per page read.

    If your site involves a log-in, then using the standard htpasswd mechanism (and ensuring user/pass combos were unique) wd give a perhaps less error-prone way to get the browser to tell you who it is - though obviously one involving more hassle for your users. OTOH if they know they are getting some personalised functionality for this hassle they may be willing to do it.

    George Sherston

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://171895]
Approved by Aristotle
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2017-12-17 22:27 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (466 votes). Check out past polls.