For an assignment I'm building a web application that starts with a user logging in. After logging in a session is created, but upon refreshing, new session IDs are being created, so state isn't being preserved. I've read about using the POST-REDIRECT-GET method to not resubmit the login form, and I'm trying to do this with my scripts. Maybe I'm misunderstanding how and what to redirect to, but this code below isn't working. It's a subroutine that is run once the user is authenticated. Any ideas of what's going wrong?
sub send_to_main {
my $session = new CGI::Session(undef, undef, {Directory=>'/tmp'});
$session->expires('+1d');
my $cookie = $q->cookie(
-name => 'jadrn015SID',
-value => $session->id,
-expires => '+1h');
print $q->header( -cookie=>$cookie );
my $sid = $session->id;
$session->param('user',$user); #added to make session more unique
print $cookie;
print $q->redirect(
-uri=>"http://jadran.sdsu.edu/perl/jadrn015/proj1_scripts/main_app.cgi",
-status=>302,
-cookie=>$cookie
);
EDIT: I am getting the 302 message back from the server, but it is being printed to my html document (I know this is because I am printing a header before I do the redirection). However, if I delete
print $q->header( -cookie=>$cookie );
Then nothing works, after logging in, my browser either says that the file is not found or it tries to download the script.