Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

cookie woes

by wolverina (Beadle)
on Nov 20, 2002 at 17:17 UTC ( [id://214532]=perlquestion: print w/replies, xml ) Need Help??

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

i'm doing my first cookie script.. but i'm having trouble.
#!/usr/local/bin/perl use CGI; $q = new CGI; $cookie_out = $q->cookie(-name=>"cookieinfo", -value=>$random,-expires=>'+24h'); print $q->header(-cookie=>$cookie_out);
That prints cookie to hard drive. Now using a different script, this should read it back in:
#!/usr/local/bin/perl use CGI; $q = new CGI; print "Content-type: text/html\n\n"; $cookie_in = $q->cookie("cookieinfo"); print $cookie_in;
Why is $cookie_in empty, and nothing being printed to the screen? -Lisa

Replies are listed 'Best First'.
Re: cookie woes
by mikeirw (Pilgrim) on Nov 20, 2002 at 17:20 UTC

    Does $random contain a value? When you read a cookie in, it only returns its -value.

      yes, $random contains a value. I want to make sure that the script that reads in the cookie isn't missing a line of code. -Lisa

        Are you executing the script within the same domain that the cookie is set for? In other words, you cannot read a cookie from a different domain.

Re: cookie woes
by dingus (Friar) on Nov 20, 2002 at 18:06 UTC
    You may want to make the browser verify that it has the cookie you expect for testing. Do this by outputting somewhere on the page(s)
    print "<script>alert(document.cookie)</script>
    Ths will make the browser open an alert window with the contents of the cookie string (i.e. all the cookies) for the page. This should include your cookie info variable.

    The most likely error - assuming that the first page has the cookie and the second doesn't is that ou have somehow changed domain.

    Dingus


    Enter any 47-digit prime number to continue.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://214532]
Approved by mikeirw
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found