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

Ive created a cookie and it's present in the cookies folder, but when i try to retrieve the data via $ENV{'HTTP_COOKIE'} i get a return value of zero. I also tried using cgi.pm, but again the cookie is created but retrieving it is a different story....any ideas?? Im running my scripts off the cgi.tripod.com domain
  • Comment on $ENV{'HTTP_COOKIE'} keep returning null even though ive created the cookie

Replies are listed 'Best First'.
Re: $ENV{'HTTP_COOKIE'} keep returning null even though ive created the cookie
by Chady (Priest) on Aug 26, 2001 at 23:49 UTC

    Without some code to work with it's hard to tell what could possibly do that.

    • how are you setting the cookie?
    • what system are you using for testing?

    Try to post some code in order to get any assistance. plus you should always use CGI.pm


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
      Thanx again, here's my code the file is named: http://cgi.tripod.com/aine_canby/cgi-bin/yop.cgi ------------------------------------------------------- Code ------------------------------------------------------- #!/usr/local/bin/perl -w use strict; use CGI; my $query = new CGI; my $cookie_out = $query->cookie( -name=>"MY_NAME", -value=>"Barry Griffin", -expires=>'+24h', -path=>'/aine_canby/cgi-bin', -domain=>'cgi.tripod.com', -secure=>0 ); print $query->header(-cookie=>$cookie_out); print $query->start_html("Cookie Test"); # DEBUG TO SCREEN print $query->p; print $query->header(-cookie=>$cookie_out); print $query->p; my $cookie_in = $query->cookie("MY_NAME"); if($cookie_in) { print $cookie_in; } else { print "Can't find the cookie"; } print $query->p; print $query->end_html; ---------------------------------------------------------- BROWSER DISPLAYS ---------------------------------------------------------- Set-cookie: MY_NAME=Barry%20Griffin; domain=cgi.tripod.com; path=/aine +_canby/cgi-bin; expires=Monday, 27-Aug-2001 22:50:49 GMT Content-type +: text/html Can't find the cookie ----------------------------------------------------------- Cookie Contains - MY_NAME Barry%20Griffin cgi.tripod.com/aine_canby/cgi-bin 0 782699264 29437766 42193056 29437564 *
      I agree with Chady, it is a bit hard to help out without seeing your code.

      Also, yes, ALWAYS, I repeat, always use CGI.pm, since it is bundled with most Perl distro's now days, leaving no excuses (usually) about "oh I can't user CGI.pm since my server doesn't support, etc."

      Last but not least, I would suggest choosing another server to do this work on... perhaps you should see jcwren's homenode, and find about Perlmonk where you can get free testing space for your stuff!

      Andy Summers
Re: $ENV{'HTTP_COOKIE'} keep returning null even though ive created the cookie
by cLive ;-) (Prior) on Aug 27, 2001 at 04:03 UTC
    And there is, of course, the slap-my-forehead-and-say-d'oh response if the answer to the following is yes...

    Are you trying to access the cookie in the same script invocation that sets the cookie?

    Only cookies sent from the browser are stored in the $ENV{'HTTP_COOKIE'} / $q->cookie() object, so if you've just set the cookie, it's not available in that object until the browser next calls the script.

    cLive ;-)

Re: $ENV{'HTTP_COOKIE'} keep returning null even though ive created the cookie
by mitd (Curate) on Aug 27, 2001 at 02:29 UTC

    First check this node. As it states 8 times out of 10 assuming that the cookie has been set correctly (your post suggest that this is so) then problem is with the server IP's. When the server returns to pick up Cookie who it says it is is not he same as who set the cookie. This can happen for various reasons. There are several environment dependent ways to test this. Please give more details about your systems environment if the suggestions in node don't help.

    mitd-Made in the Dark
    'My favourite colour appears to be grey.'

Re: $ENV{'HTTP_COOKIE'} keep returning null even though ive created the cookie
by Ryszard (Priest) on Aug 27, 2001 at 05:21 UTC

    I had a similar problem doing this. my slap in the face with a wet fish problem was the path and domain vars set in the cookie.

    Make sure the script your trying to get the cookie from fits within the parameters you set for path and domain

Re: $ENV{'HTTP_COOKIE'} keep returning null even though ive created the cookie
by orkysoft (Friar) on Aug 27, 2001 at 17:24 UTC

    Test on another server to see if it works there. If it does, it means the cgi.tripod.com server doesn't allow cookies to be read by CGI programs. Some free CGI hosts are more fascist than is necessary to have your program run on time.

    You could try Prohosting.com, which I'm pretty sure still supports cookies, or your own local server, which you can configure however you want. Only if your program worked on either of these servers, and not on the Tripod one, is it Tripod's fault.

    Good luck, and don't forget to have some fun!