I'm using Perl CGI and I got 3 script for an login system.

index.pl -> user needs to input stuff here
login.pl -> getting called if the user hits the login button - checks if the enteres stuff is the same in database
result.pl -> getting redirected to this if the login was successfull.

login.pl
# Includes use strict; use warnings; use CGI; use DBI; use Digest::MD5 qw(md5 md5_hex md5_base64); # Get Parameters my $p_sUsername = param( 'username' ); my $p_sPassword = param( 'password' ); $p_sPassword = md5_hex( $p_sPassword ); if ( !defined( $p_sUsername ) || !defined( $p_sPassword ) ) { print redirect( "access-denied.pl" ); } # DB Stuff done here ... my $oCGI = CGI->new(); my $oCookie = $oCGI->cookie( -name => "user", -value => $p_sUsername -expires=>'2h' ); print redirect( "result.pl", $oCookie );


result.pl
my $oCGI = CGI->new(); print $oCGI->cookie('user'); # this is empty
What am I doing wrong? I need to pass data from page to page to be able to check if a user is authenticated or not ...

Update:
Seems like I had to use print $oCGI->redirect( -uri => "orders.pl", -cookie => $oCookie );. Now I can get the username on the second page ...

In reply to Perl Sessions and Cookies - Cookie don't get passed by Yaerox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.