Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Basic Cookie Getting/Setting

Posted on 1999-07-06
Medium Priority
Last Modified: 2010-03-04
I have the following two scripts:
#!/usr/bin/perl -w
use CGI qw(:standard);

$usercookie = cookie( -NAME => "foo",
                      -VALUE => "saved_data",
                      -EXPIRES => "+2y" );
print header(-COOKIE => $packed_cookie);

print "Tried to set cookie<BR>\n";  
use CGI qw(:standard);

$data = cookie("foo");

print header();

print "from cookie got $data<BR>\n";    
But when I run setcookie then getcookie, I don't
get the cookie information.  When I close out netscape
the cookie.txt file doesn't show anything either.  
Anything I'm obviously doing wrong here?
obviously wrong?
Question by:kisrael
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

lordvorp earned 210 total points
ID: 1213890
I'm almost embarrassed to answer this one:
#!/usr/bin/perl -w
use CGI qw(:standard);

$usercookie = cookie( -NAME => "foo",
^^^^^^^^^^^           -VALUE => "saved_data",
                      -EXPIRES => "+2y" );

# establishing a variable called $usercookie

print header(-COOKIE => $packed_cookie);
# uses a previously undefined value for the cookie, which of course has a null response.                              

Author Comment

ID: 1213891

Man, I snipped this test code from a slightly more complex script I was starting for clarity, where $usercookie was the name of the cookie (instead of foo) but of course I copied this error right along with it.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question