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

Dear monks,

I used the below code to set the cookie in my system. i am getting error. please any one help me.

Thanks

#!/usr/bin/perl use CGI; use HTTP::Cookies; my $q = new CGI; my $status=$q->cookie('ckname'); &set_cookie($status); sub set_cookie { my($cookieid)=shift; my @cookies = ($q->cookie(-name=>"ckname", -value=>$cookieid, -expires=>'', -path=>'/', -domain=>'.bn.whsites.net')); print $q->header(-cookie=>\@cookies); }

Replies are listed 'Best First'.
Re: Error in my code while set cookie?
by pg (Canon) on Oct 05, 2005 at 02:28 UTC

    The problem is with the $status you passed in, and it is not defined. If you pass in a valid value, the cookie will be generated.

    use CGI; use HTTP::Cookies; use Data::Dumper; my $q = new CGI; my $status=$q->cookie('ckname'); &set_cookie('abc'); sub set_cookie { my($cookieid)=shift; my @cookies; push @cookies, $q->cookie(-name=>"ckname", -value=>$cookieid, -expires=>'', -path=>'/', -domain=>'.bn.whsites.net'); print $q->header(-cookie=>\@cookies); }

    Thsi gives:

    Set-Cookie: ckname=abc; domain=.bn.whsites.net; path=/ Date: Wed, 05 Oct 2005 02:29:51 GMT Content-Type: text/html; charset=ISO-8859-1

      I am reading and printing the text from cookie but, i can't what error may be

      #!/usr/bin/perl use CGI; use HTTP::Cookies; use Data::Dumper; my $q = new CGI; my $cookie_jar = HTTP::Cookies->new; my $status=$q->cookie('ckname'); &set_cookie('abc'); $response = '.bn.whsites.net'; my $cjar = HTTP::Cookies->new; $cjar->extract_cookies($response); my $cookie = $cjar; print $cookie; sub set_cookie { my($cookieid)=shift; my @cookies; push @cookies, $q->cookie(-name=>"ckname", -value=>$cookieid, -expires=>'+2h', -path=>'/', -domain=>'.bn.whsites.net'); print $q->header(-cookie=>\@cookies); }
      Thanks pg! now it's working. Thank you very much
Re: Error in my code while set cookie?
by GrandFather (Saint) on Oct 05, 2005 at 02:25 UTC

    What error and how do you know? When I run your code I get the following output (what do you expect to get?):

    Date: Wed, 05 Oct 2005 02:23:43 GMT Content-Type: text/html; charset=ISO-8859-1

    Perl is Huffman encoded by design.
      Cookie file not created to me. If any error in code in creation of cookie file please tell me