Why doesn't this code set the cookie properly? No cookie gets set with this code, and I can't understand why? Thanks for any input you guys can give me.
#######################################################################################
sub get_unique_id {
my $randlet = chr(65 + int(rand(26))) . chr(65 + int(rand(26)));
my $randnum = 100_000 + int rand 900_000;
my $randid = $randlet . $randnum;
&connect_to_db;
$sth = $dbh->prepare("SELECT id FROM bs_sessions WHERE id = $randid");
$sth->execute();
my $isnumrand = $sth->fetchrow_hashref;
$sth->finish();
if ($isnumrand->{id}) {
&get_unique_id;
}
return $randid;
}
#######################################################################################
#######################################################################################
sub set_cookie {
&get_unique_id;
$cookie_id = $query->cookie (
-name => 'id',
-value => $randid,
-expires => '+1w',
-path => '/',
-domain => 'fbagroup.co.uk'
);
print $query->header(-cookie=>[$cookie_id]);
}
- wil
Code:
####################################################################################### #######################################################################################
sub get_unique_id {
my $randlet = chr(65 + int(rand(26))) . chr(65 + int(rand(26)));
my $randnum = 100_000 + int rand 900_000;
my $randid = $randlet . $randnum;
&connect_to_db;
$sth = $dbh->prepare("SELECT id FROM bs_sessions WHERE id = $randid");
$sth->execute();
my $isnumrand = $sth->fetchrow_hashref;
$sth->finish();
if ($isnumrand->{id}) {
&get_unique_id;
}
return $randid;
}
#######################################################################################
#######################################################################################
sub set_cookie {
&get_unique_id;
$cookie_id = $query->cookie (
-name => 'id',
-value => $randid,
-expires => '+1w',
-path => '/',
-domain => 'fbagroup.co.uk'
);
print $query->header(-cookie=>[$cookie_id]);
}
- wil