ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-unix-users
perl-unix-users
RE: [Perl-unix-users] IE6 -> Perl Cookies - Unix/Linux vs. Window s
by Jon Earle other posts by this author
Apr 17 2003 7:32AM messages near this date
RE: [Perl-unix-users] Installing ActiveState's perl 5.8 on Red Hat 9 | RE: [Perl-unix-users] IE6 -> Perl Cookies - Unix/Linux vs. Window s
On Thu, 17 Apr 2003, Lingtren.com wrote:

>  I used following code:
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  print "Set-Cookie:xxx=yyy\n";
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  use strict;
>  use CGI ':standard';
>  $q = new CGI;
>  my $cookie1 = $q->cookie(-name=>"xxx",-value=>"yyy");
>  print $q->header(-cookie=>[$cookie1]);
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Well, you're trying to set two cookie headers here.  The cookie code I use is
much like this:

    use CGI qw(-no_xhtml);

    my $cookie = new CGI::Cookie(-name    =>  'credentials',
                                 -value   =>  [$username, $passwd],
                                 -expires =>  '+2M');           # Valid for 2 months

    my $query = new CGI;
    print $query-> header(-cookie=>$cookie);

This creates a persistent cookie; if you just want a session cookie, just
remove the '-expires' key.

Reading it back it easy too:

    my ($username, $passwd) = "";
    my %cookies = parse CGI::Cookie($ENV{HTTP_COOKIE});

    if (%cookies) {
        if ($cookies{'credentials'}) {
            ($username, $passwd) = $cookies{'credentials'}-> value;
        }
    }

I found http://www.perldoc.com/perl5.6.1/lib/CGI/Cookie.html helpful when
figuring all this out recently.

Cheers!
Jon

---
Jon Earle

SAVE FARSCAPE http://www.savefarscape.com/

While it's okay to disagree with your freinds and family, childish insults
do not express sovereignty.

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved