Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

inserting and using cookies

by clickit (Initiate)
on Jan 24, 2006 at 14:10 UTC ( [id://525178]=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,

I used cookie.lib to insert and retrive cookies for my CGI/Perl e-commerce application. While I set the cookies to expire after three hours, the cookies lasted only for the current browser session.

($ss, $mm, $hh, $dom, $mon, $yr, $wkd, $doy, $idt) = gmtime(time + 155 +52000); @Mth = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec'); @Day = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); $SetYear = 1900 + $yr; $SetDay = $Day[$wkd]; $SetMonth = $Mth[$mon]; $SetDOM = sprintf('%02d', $dom); &SetCookies('HBL5USERID',"$userid"); &SetCookieExpDate("$SetDay, $SetDOM-$SetMonth-$SetYear $hh:$mm:$ss GMT +"); &SetCookieDomain('.healthbliss.net');
Did I do anything wrong with the above codes? Any help or comment would be deeply appreciated. Thank you!

Best regards,
Patrick

Replies are listed 'Best First'.
Re: inserting and using cookies
by davorg (Chancellor) on Jan 24, 2006 at 16:12 UTC

    When you call SetCookies, you haven't set the expiry date, so your cookie is set with the default expiry date. Try calling SetCookies after you have set all of the required attributes of the cookies.

    Alternatively, stop using cookielib and just use the underlying CGI::Cookie calls. You'll have far more control over what is going on, and it's really no harder to do.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Hi, Dave:

      Thank you for the advice! Where can I get the documentation on how to use CGI::Cookie?

      Appreciated,
      Patrick

        The CGI::Cookie documentation on CPAN would be an obvious place to start. Also you might find the first half of this article to be useful.

        --
        <http://dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

Re: inserting and using cookies
by guha (Priest) on Jan 24, 2006 at 14:41 UTC

    I have not used cookie.lib myself, so now I'm guessing ..

    Have you included the cookie in the page you send to the browser ?

    print "Content-type: text/html\n"; &SetCookies('name',"$name",'email',"$email"); print "\n";

    The symptoms you describe sounds alot like either the above or that the SetCookieExpDate call didn't work.

    Or perhaps the order is essential, aka you need to call SetCookies after SetCookieExpDate ?

      Hi, guha:

      Yes, the SetCookieExpDate call didn't work because SetCookies must be called after SetCookieExpDate. I didn't realize the order is essential. It works now! Thanks!

      Appreciated, Patrick
Re: inserting and using cookies
by northwind (Hermit) on Jan 24, 2006 at 14:42 UTC

    If your users were using Firefox, what you are seeing would make sense.  Firefox has a feature to automatically expire cookies when you close the browser.  Or am I not understanding your question?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://525178]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found