Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: cookie problem

by bigup401 (Pilgrim)
on Nov 12, 2014 at 18:51 UTC ( [id://1107009]=note: print w/replies, xml ) Need Help??


in reply to Re^4: cookie problem
in thread cookie problem

this is the full script

HOME.PL use DBI; use CGI; use strict; my $cgi = CGI->new(); my $db ="databa"; my $usr ="root"; my $pwd =""; my $host ="localhost"; my $dbh = DBI->connect("DBI:mysql:$db:$host", $usr, $pwd { AutoCommit => 0, RaiseError => 1, } ) or die $DBI::errstr; my $username = $cgi->param('username'); my $password = $cgi->param('password'); my $sth = $dbh->prepare("select id from mysql_auth where username=? AN +D password=?"); $sth->execute($username,$password) if(my $x = $sth->fetchrow()); { $sth->finish(); my $cookie = $cgi->cookie( -name => 'login', -value => $username, -expires => '+2m', -path => '/'); print $cgi->redirect(-url=>"welcome.pl", -cookie=>$cookie); } else { print"wrong password\n"; } WELCOME.PL use DBI; use CGI; use strict; my $cgi = CGI->new(); $sid = $cgi->param('login'); if ( ! $sid ){ # exit and return to home.pl! we have no cookies print $cgi->redirect(-uri=>"home.pl", -cookie=>$cookie); } else { #start using the page! we have cookies print $cgi->header(-cookie=>$cookie); }

Replies are listed 'Best First'.
Re^6: cookie problem
by fishmonger (Chaplain) on Nov 12, 2014 at 22:56 UTC

    I see several issues, but the key one is this one in wel.pl
    $sid = $cgi->param('login');

    You don't retrieve cookie data via the param() method, you retrieve it using the cookie() method.
    my $sid = $cgi->cookie('login');

      i tried it as u said bt still redirect me back

        Where is the username and password entered ?

Re^6: cookie problem
by poj (Abbot) on Nov 12, 2014 at 19:16 UTC
    If you show your complete scripts we can probably help you.
    poj

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1107009]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-29 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found