in reply to Re^4: Cookie Problems
in thread Cookie Problems

Without seeing the rest of your code, I can only speculate, but are you printing a header anywhere before this point? You can print only one and if you want to set a cookie, you have to do it there.

Apologies if you already know this; it's a common mistake that trips up everybody at least once, though.

Replies are listed 'Best First'.
Re^6: Cookie Problems
by intranetman (Acolyte) on Sep 30, 2004 at 19:04 UTC
    Yes, when I set the cookie I print the header. Here is the sub for that:

    sub setCookie($) { my($session) = @_; my $query = new CGI; $sid = $session->id(); $cookie = $query->cookie(-name => "CGISESSID", -value => $sid, -expires => '+1h'); -path => '/tmp/Sessions'); print $query->header(-cookie=>$cookie);

    Then attempt to retrieve the cookie here:

    sub retrieveSession($) { my ($query, $session) = @_; $sid = $query->cookie(CGISESSID=>$session->id) || undef; $sid = substr($sid, 10, -8); $session = new CGI::Session(undef, $sid, {Directory=>'/'}); return getUser($session, $sid); }