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

Dear monks
i am trying to set cookies, which seem to be working ok since the code doesnt throw any errors or warnings. I've my web browser set to prompt for cookies, so if they'd worked i should be prompted. it seems to just ignore it! here is the code that should first check for cookies and then set if none:
sub login { if (exists $row[0], $password eq $row[1]) { $cookie = $q->cookie(-name=>"username" ) || set_cookie($q); $cookie1 = $q->cookie(-name=>"userpass" ) || set_cookie_pass($q); print $q->header(-type=>"text/html"), $q->start_html(-title=>" | Admin | ", -style=>{-src=>"../. +./mycss.css"}), $q->end_html; } else { error_page(); exit; } } ################################################# sub set_cookie { my $q = shift; my $username_sub= $q->param('username'); $cookie = $q->cookie( -name=>"username", -value=>$username_sub, -expires=>"+30m"); } sub set_cookie_pass { my $q = shift; my $password_sub = $q->param('password'); $cookie1 = $q->cookie(-name=>"password", -value=>$password_sub, -expires=>"+30m"); }
any ideas appreciated.cheers
r_mehmed

Replies are listed 'Best First'.
Re: Trouble with cookies
by pfaut (Priest) on Mar 07, 2003 at 02:17 UTC

    You need to include the cookies when you send the header.

    $cookie = $q->cookie(-name=>"username",-value=>$username); print $q->header(-cookie=>$cookie);

    You should also read merlyn's column on the subject.

    --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
Re: Trouble with cookies
by blokhead (Monsignor) on Mar 07, 2003 at 02:21 UTC
    You create the cookies, but never send them to the browser. Perhaps something like this:
    print $q->header(-type=>'text/html', -cookie=>$cookie, -cookie=>$c +ookie1);

    blokhead