in reply to Problem retrieving session cookies

CGI passes this information to CGI::Cookie, which includes an expiration if -expires is defined, since an empty value is defined, you get an expiration date. Instead of passing an empty value, just leave that line out altogether:

$initcookie = $q->cookie( -name=>'User_Session', -value=>'abc', -path=>'/', -domain=>'www.thedialogcenter.com', -secure=>0 );

We're not surrounded, we're in a target-rich environment!

Replies are listed 'Best First'.
Re: Re: Problem retrieving session cookies
by Hammy (Scribe) on Apr 10, 2003 at 03:19 UTC
    Thanks for the advice. I tried to just remove it and it did not seem to make a difference. Still when I try to grab the value of the cookie and print it out, I don't get anything. I added the following print statement print $q->header(-cookie=>$initcookie); and what follows is the result (I'm guessing it is not actually printing what is in the cookie, but rather what I am trying to put in the cookie)
    Set-Cookie: User_Session=abc; domain=www.thedialogcenter.com; path=/ Date: Thu, 10 Apr 2003 03:11:44 GMT Content-Type: text/html; charset=ISO-8859-1
      No - that is the cookie it's printing. Remember that a cookie is simply another HTTP header line printed by your script -in the example code you posted, you weren't actually printing the cookie anywhere. As jasonk says, you should be able to just print the cookie with *no* expiry date defined and it automatically becomes a session cookie.

      Cheers,
      Ben
        Thanks for your response Ben. I finally got it to work (somewhat). When I moved the print "Content-type: text/html\n\n"; until after the calls to the cookie it worked. Now looks like this:
        $q = new CGI; my $cookievalue = $q->cookie('User_Session'); $initcookie = $q->cookie( -name=>'User_Session', -value=>'abc', -path=>'/', -domain=>'www.thedialogcenter.com', -secure=>0 ); print $q->header(-cookie=>$initcookie); print "Content-type: text/html\n\n"; print "The cookie value is : $cookievalue<br>";
        My first question is why (I hate doing things that work that I don't understand). My second question - is there a way to set the cookie after the "Content-type" has been set? Third questions -why do my questions not show up in the main list of questions. And finally, why do I no longer get an email when someone responds. I asked a question a while ago about sessions and got some GREAT responses that I never looked at because I thought I would get an email when they responded. Thats in advance for answers to any of my questions.