Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Location
    Malaysia
    Posts
    29

    Angry Unanswered: problem to retrieve cookie

    I have this program, where it can set the cookie, and produce the header like:

    Set-Cookie: student_login=pearloh; path=/ Date: Tue, 15 Jun 2004 04:13:38 GMT Content-Type: text/html; charset=ISO-8859-1

    i have set the cookie in perl this way:

    my $student_cookie = cookie(-name => 'student_login',
    -value=> $student_login);
    print header(-cookie =>$student_cookie);


    but, the following web page after this page, cant seemed to retrieve the cookie...

    <td width="20%">
    <div align="left">
    <font color="#ffffff" size="1"><b>
    <font face="Verdana, Arial, Helvetica, sans-serif">
    $student_login Answer</font></b></font></div>
    </td>


    Please HELP...

  2. #2
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    You have to get the cookies' value. You can do like this:

    skript1:
    Code:
    #! /usr/bin/perl
    
    use strict;
    use warnings;
    use CGI;
    use CGI::Carp qw(fatalsToBrowser);
    
    my $cgi = CGI->new();
    my $cookie = $cgi->cookie(-name => 'student_login', -value => $student_login);
    print $cgi->header(-type => 'text/html', -cookie => $cookie),
           $cgi->start_html(),
           $cgi->h2('The cookie is set'),
           $cgi->end_html();
    skript2:
    Code:
    #! /usr/bin/perl
    
    use strict;
    use warnings;
    use CGI;
    use CGI::Carp qw(fatalsToBrowser);
    
    my $cgi = CGI->new();
    my %cookie_values = $cgi->cookie('student_login');
    print $cgi->header(-type => 'text/html'),
           $cgi->start_html(),
           $cgi->h2("The cookies' value is ".$cookie_values{value}),
           $cgi->end_html();
    board.perl-community.de - The German Perl-Community

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •