in reply to Cookie, redirect

I whipped up this little test which both set the cookie and redirected my browser.
#!/usr/bin/perl use warnings; use strict; use CGI; my $query = new CGI; my $cookie = $query->cookie(CGISESSID => 'werd'); print $query->header( -cookie=>$cookie, -location=>'http://www.google. +com/' ); #<-- this is the important line! exit;
You should be able to adapt it to your needs.

Replies are listed 'Best First'.
Re^2: Cookie, redirect
by Anonymous Monk on Jul 21, 2005 at 21:20 UTC
    thanks for the reply,
    yes, you code doesn't work,
    Im still in login page, with this lines displayed:
    Set-Cookie: CGISESSID=e7ed07c2bae89b1ff8418f42889538b5; path=/ Date: Thu, 21 Jul 2005 21:17:13 GMT Location: http://localhost/cgi-bin/welcome.pl Content-Type: text/html; charset=ISO-8859-1
    is there something wrong with IE?
      Hmm, it worked for me. Are you using CGI.pm? Can you post the code? Maybe there's something else you're overlooking.
        here you are,
        also are running apache server with perl
        #!c:/perl/bin/perl.exe -w $cfh = select (STDOUT); $| = 1; select ($cfh); #the above line is to provide the scripts interpreter location-------- +>scripts: login.pl #---------------------------------------session_start.pl #---------------------------------------#include the libraries: use CGI qw/:standard/; # load standard CGI routines use CGI; #load the object orentird CGI use DBI; # load DBI library use CGI::Session; # load the Session library use CGI::Carp qw(fatalsToBrowser); # load CGI-Carp for browser er +rors handling my $query = new CGI; #---------------------------------------# if( $query->param("Submit") ){ our $message; #-------check the login if ($query->param("login")) { $login1 = $query->param("login"); unless ($login1 =~ /^[a-z0-9_]+$/) { $login = ''; $message .= 'The login ID contains invalid character!<br>'; }else{ $login = $query->param("login") } }else{ my $login = ''; $message .= 'You forget to enter your login ID!<br>'; } #-------check the password if ($query->param("password")) { $password1 = $query->param("password"); unless ($password1 =~ /^[a-z0-9_]+$/) { $password = ''; $message .= 'The password contains invalid character!<br>'; }else{ $password = $query->param("password") } }else{ my $password = ''; $message .= 'You forget to enter your password!<br>'; } if ($login && $password) { #---------------------- my $sqlstatement="bla bla"; my $sth = $dbh->prepare($sqlstatement); $sth->execute || die "Could not execute SQL statement ... maybe invali +d? $DBI::errstr"; my @row=$sth->fetchrow_array; if (@row) { our $first_name = $row[0]; our $last_name = $row[1]; our $user_id = $row[2]; our $admin = $row[3]; our $user_address = $row[4]; #----------create the user session my $session = new CGI::Session("driver:File", $query, {'Directory' => +"C:\\session\\"} ) or die "S!"; $session->header(); my $session_id = $session->id(); #get the session I +D $session->param('username', $username); #add the username +to the session $session->param('user_id', $user_id); #add the user_id t +o the session $session->param('first_name', $first_name); #add the first_nam +e to the session $session->param('last_name', $last_name); #add the last_name + to the session $session->param('address', $user_address); #add the address t +o the session $session->param('admin', $admin); #add the admin ide +ntity to the session #save session params in the $query object $session->expire('+10m'); #session should e +xpire after 10 minutes $cookie = $query->cookie(CGISESSID => $session->id); print $query->header( -cookie=>$cookie ); print $query->header(-type => 'text/html', -cookie=>$cookie, -location +=>'http://localhost/cgi-bin/cars/loggedin.pl' ); exit; #-------------- finish MySQL statement $sth->finish(); #-------------- disconnect from database $dbh->disconnect(); }else{ $message .= 'The username and the password do not match <br>t +hose in the record.<br>'; } }else{ $message .= 'Try again.'; } } #---------the param bracket