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

HI all, I am trying to set up cookies for storing my username and use them later on while requesting other CGI pages. But the problem is either the cookies are not getting set up or they are not getting retrieved. Where are they stored? so that i can see them. Also I am using IIS server and Fire Fox and IE6.0 as web browsers. Please help and let me know what is the exact probelm? Thanks!!
# Create new cookies and send them my $cookie1 = new CGI::Cookie(-name=>'user_id',-value=>$username); print CGI::header(-cookie=>[$cookie1]); $cookie1->bake; #retrieving cookies my %cookies = raw_fetch CGI::Cookie; print %cookies; foreach (keys %cookies) { print ($cookies{$_}); }

Replies are listed 'Best First'.
Re: cookies not getting setup
by Corion (Patriarch) on Dec 04, 2007 at 07:01 UTC

    You have diagnosed the problem quite well already:

    But the problem is either the cookies are not getting set up or they are not getting retrieved.

    Cookies are stored in your browser(s). Find out where exactly.

    Have you checked that your script sends the cookie header?

    Your way of getting at the cookies via raw_fetch is not what the documentation says, maybe there is a problem.

    I recommend the HTTP Live Headers and/or a network sniffer to check what is actually being sent to and from the browsers to better find out where the problems lie.

      Thanks! The cookie is getting printed on the browser but where it is stored i am not sure.. its not there in browser cookies. i am returned nothing on retrieval.

        If the cookie is not stored in your browser, then that's a problem with your browser. Have you tried turning off all anti-spyware stuff, all browser plugins and such? Have you tried with alternative browsers, like lynx or WWW::Mechanize to see whether they accept the cookie?

        How did you see that "The cookie is getting printed on the browser" ?

        A reply falls below the community's threshold of quality. You may see it by logging in.

        Try this (in Firefox): Tools->Options...->Privacy->Cookies Tab->View Cookies button.

        In the list you must find your server domain name and cookies which are set by this server (you can use Search field at the top).

        If you can't find your cookies than maybe you did't send cookies header correct (maybe you print them after \n\n?). You can use LiveHTTPHeader Extension with Firefox to see which info your browser get from server.