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

Hi I've the following code to create a cookie when a user login into my webapp
$cookie = CGI::Cookie->new(-name => 'USERNAME', -value => $encrypted, -expires => '+3M', -path => '/cgi-bin/recordz', -secure => 1); print $query->header(-cookie=>$cookie);
then after I attempt to read the value back in my code
local our $cookie_in = $query->cookie('USERNAME'); print "Content-Type: text/html\n\n"; print $cookie_in;
$cookie_in is always empty but in the cookie manager the cookie exist and got the correct values any idea welcome thanks

Replies are listed 'Best First'.
Re: cookie created but impossible to read it
by moritz (Cardinal) on Apr 05, 2014 at 10:18 UTC

    Are you accessing the CGI script with HTTPS? If not, -secure => 1 will prevent the browser from sending it.

    Also, you can (and should) debug all the steps that the cookie takes. For example with firebug (a firefox extension), you can see the whole HTTP response, including headers. Is the Set-Cookie line like you'd expect it?

    If yes, next step: in the browser, list all cookies for your domain. Is it there?

    If yes, next step: initiate another HTTP request from the browser, inspect the HTTP request. Is the cookie in there?

    If you can answer all of those questions with "yes", you know that you have a problem with reading the cookie. Otherwise it's a problem with setting the cookie (or possibly a step inbetween).

      thanks the path was wrong it's work fine rigth now :)
Re: cookie created but impossible to read it
by Anonymous Monk on Apr 05, 2014 at 09:48 UTC