in reply to Re: Problem retrieving session cookies
in thread Problem retrieving session cookies

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

Replies are listed 'Best First'.
Re: Re: Re: Problem retrieving session cookies
by benn (Vicar) on Apr 10, 2003 at 10:10 UTC
    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.
        in order....
        • You need to create the cookie, then print the cookie...It looks like you should be getting duplicate header/cookie lines there - the "print $q->header(-cookie...)" *should" do exactly the same as your next two print statements. If not, try "$q->header({-cookie=>$initcookie})" - I've known some versions of CGI.pm not like named params unless they're an anon. hash.
        • Yes - you can print the "Content-type" header, set your cookie, then print the cookie, as you can do above simply by moving the $initcookie initalisation down two lines. If you do this, you don't need to use $q->header();
        • If you mean the 'Monastery Gates' (the front page), then only certain questions make it on there - particularily interesting, informative or challenging ones usually. If you mean the "Seekers Of Perl Wisdom" section, then occasionally there may be a delay while your question is 'approved' - or maybe deleted if the question is seen as irrelevant / non-perl / flaming etc.
        • I don't *think* there's an email bot around - but in your 'preferences' you can tick the "show me when I get a response to posts" box though to receive notifications in the Chatterbox
        Hope this helps.

        Cheers,
        Ben