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

Hi Friends, I got an issue to discusss in here. I got a server X running a CGI script. After the user logs in, he is supposed to be redirected to a new server Y. Could you please give me the code for that. I was having the following code, but it doesnot work well.
#!/Usr/bin/perl use HTTP::Request::Common qw(POST); use LWP::UserAgent; use CWT::MySQL; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; my $cwt = new CWT::MySQL(); my $url = $cwt->url; my $cgi = new CGI; $cwt->set( page_title => "CAVE Software"); my $action = $cwt->param('action'); # Function map for setting permissions and for specifying the action b +uttons my %FunctionMap = ( SHOW_INDEX => { ROLES => [] }, SHOW_LOAD => { ROLES => [] }, SHOW_ML => { ROLES => [] }, SUBMIT_FORM => { ROLES => [] }, AUTO => { ROLES => [] }, SHOW_ETOOLS => {ROLES=> []}, ); # # Map verbose parameter names into short versions and set the command # to 'AUTO' if it isn't defined in the FunctionMap. # my $cmd = $cwt->param('CMD') || 'AUTO'; foreach (keys %FunctionMap) { $cmd = $_ if ($cmd eq $FunctionMap{$_}{BUTTON}); } $cmd = 'AUTO' unless defined $FunctionMap{$cmd}; $cwt->set( MAN_SECTION => $cmd ); # # Send'em packin' if they don't have permission to see this function. # $cwt->require_role($FunctionMap{$cmd}{ROLES}); #print $cwt->header(); #print $cwt->start_html(); print $cgi->header(); print $cgi->start_html(-title=>"CAVE Software"); # # SHOW_INDEX -- to see index.php # if ($cmd eq 'SHOW_INDEX') { show_index(); } elsif ($cmd eq 'SHOW_ETOOLS') { show_etools(); } else { print qq{<P>Invalid command ($cmd)}; } #print $cwt->end_html(); print $cgi->end_html(); exit 0; sub show_etools { my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->env_proxy; my $response = $ua->get('http://aristotle.eng.auburn.edu/Versi +on9/index.php'); if ($response->is_success) { print $response->content; }else{ die $response->status_line; } } #################################### # submit_form #################################### sub submit_form { my %form; my $pars; my $temp; foreach my $p (param()) { $form{$p} = param($p); $temp = $form{$p}; $pars .= qq{$p=>"$temp",}; } my $faction = qq{http://aristotle.eng.auburn.edu}; $faction .= $action; my $ua=LWP::UserAgent->new(); my $req= POST "$faction",Content=>\%form; my $content=$ua->request($req); if ($content->is_success){ print $content->content; }else{ print $content->status_line . "\n"; } } #################################### # main_links #################################### sub main_links { print qq{<p><table align="center" width="100%"><tr><td>\n}; print qq{<table border="0" cellpadding="4" cellspacing="4" width=" +90%">\n}; print qq{<center><font size=+3>CAVE Software</font></center>}; print qq{<tr><td><br><ul>\n}; print qq{<li>\n}; print qq{<a href="$url?CMD=SHOW_ETOOLS">Click to user eTools</a></ +li>\n}; print qq{</li></ul></td></tr></table>\n}; print qq{</td></tr></table>\n}; }
Please help me out. I know nothing about CGI Scripting Thanks in advance sri

Replies are listed 'Best First'.
Re: Redirection from a server.
by Anonymous Monk on Aug 27, 2008 at 14:26 UTC

      Absolute URIs are required by the HTTP spec. Calling redirect as a method in this context doesn't have a benefit over calling it as function and is probably slower.

      perl -MCGI print CGI::redirect( CGI::url(-base => 1) . "/Y" );
        Y is a new server, so that makes no sense