Problems? Is your data what you think it is? PerlMonks

### Why can't I access a cookie I have set?

by cLive ;-) (Prior)
 on Jan 29, 2002 at 10:10 UTC Need Help??
Contributed by cLive ;-) on Jan 29, 2002 at 10:10 UTC
Q&A  > CGI programming

#### Description:

<question type="common">
I use CGI.pm to set my cookie, but when I try to read it, it's not there.

What gives?
</question>

 Answer: Why can't I access a cookie I have set?contributed by cLive ;-) Let's assume you have a CGI object: my $q = new CGI; [download] Cookies are accessed through$q->cookie('name'). Cookies are sent by the browser when requesting the page. If you set a cookie in a CGI script, the cookie is sent to the browser, but not set in $q->cookie. ie, Set == Cookie stored in browser Readable == Cookie available in$q->cookie('name') Event Set? Readable? Browser request n n Response to Browser y n Subsequent Browser y y Requests(*) [download] (*) - within the life of the cookie. Just remember that $q->cookie only contains cookies sent by the browser as part of that particular http request! Hope that clears things up a little :) cLive ;-) Answer: Why can't I access a cookie I have set?contributed by simon.proctor Referring to the CGI documentation, the following example is presented. $cookie = $query->cookie(-name=>'sessionID', -value=>'xyzzy', -expires=>'+1h', -path=>'/cgi-bin/database', -domain=>'.capricorn.org', -secure=>1); print$query->header(-cookie=>\$cookie); [download] I would recommend that you read the pod for CGIand use the code presented there. As a pointer, I would stick to the CGI module and not use CGI::Cookie. I say this as I've had no end of problems with CGI::Cookie in the past that disappeared once CGI was used instead. Note that the code example assumes you have already created a CGI query object. Hope that helps.

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
 [Corion]: thezip: start "some title" path\to\that\ application, but that will open another console window [Corion]: thezip: If you want to confuse your users, use system(1, "that\\command" );, which will make Perl launch it in the background [Corion]: That will keep the console window open even though the user can't type into it anymore [thezip]: So I have a script that generates a log file. After script completion, I want tohave VIM open this logfile. [thezip]: i don't get the command line "back" until I close VIM. No what I want to happen... [thezip]: I currently don't have access to CYGWIN, else I'd just do a tail -f on the logfile.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2017-03-27 18:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should Pluto Get Its Planethood Back?

Results (321 votes). Check out past polls.