Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect

Status
Not open for further replies.

sulfericacid

Programmer
Aug 15, 2001
244
US
Hello,

I created a mail form which the source will be below. The only problem with the script is the redirection part at the end. It is supposed to redirect to thanks.html. What does it do? It prints 'Location: onto the browser screen.

Can someone tell me how to stop making it print and start redirecting?

Thanks.

-Acid

Code:
#!/usr/bin/perl
print "Content-type: text/html\n\n";

######################################################################
##########################VARIABLES/MUST EDIT########################
use CGI qw:)standard) ;

my $adminemail = param("adminemail");
my $webmastername = param("webmastername");
my $recipientemail = param("recipientemail") ;
my $visitorname = param("visitorname");
my $weburl = param("weburl");
my $subject = param("subject");
my $subject2 = param("subject2");
my $message = param("message");
my $autoresponse = param("autoresponse");

# Change with your email account
$adminemail='sulfericacid@qwest.net';

# Change to correct path of sendmail
$sendmail='/usr/sbin/sendmail';

# Homepage url, do not link to form, use your index. Ie. "$homepage='
# Change to enclosure. Ie. "Sincerly yours"
$thanks='Thank you for visiting our site, please come again!';

# Change to page redirect.
$redirect='# Change to autoresponse.
$autoresponse ='This is an autoresponse from SpyderSubmission. Your message was received. If you are awating a response, please allow upto 8 hours';

######################################################################
#######################FORM PARSING/DON'T EDIT########################
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
$buffer = $ENV{'QUERY_STRING'};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}

if ($recipientemail) {
unless ($recipientemail =~ /\w+@\w+.\w+/) {
print &quot;<H1><CENTER><FONT COLOR=RED>OOPS!</FONT></CENTER></H1>\n\n\n\n&quot;;
print &quot;Sorry, the email address <font color=red>$recipientemail </font> is invalid. Please try again\n&quot;;

exit;
}
}

######################################################################
#######################EMAIL TO VISITOR/DON'T EDIT######################
open(MAIL,&quot;|$sendmail -t&quot;);
print MAIL &quot;To: $recipientemail\n&quot;;
print MAIL &quot;From: $adminemail\n&quot;;
print MAIL &quot;Subject: $subject\n&quot;;
print MAIL &quot;Greetings, $visitorname\n\n&quot;;
print MAIL &quot;$autoresponse\n\n&quot;;
print MAIL &quot;You wrote-$message\n\n&quot;;
print MAIL &quot;$thanks\n&quot;;
print MAIL &quot;$webmastername\n&quot;;
print MAIL &quot;mailto:$adminemail\n&quot;;
print MAIL &quot;$homepage\n&quot;;
close(MAIL);

######################################################################
#######################EMAIL TO ADMIN/DON'T EDIT#######################
open(MAIL,&quot;|$sendmail -t&quot;);
print MAIL &quot;To: $adminemail\n&quot;;
print MAIL &quot;From: $recipientemail\n&quot;;
print MAIL &quot;Subject: $subject2\n&quot;;
print MAIL &quot;Name- $visitorname\n&quot;;
print MAIL &quot;Email- $recipientemail\n&quot;;
print MAIL &quot;URL- $weburl\n&quot;;
print MAIL &quot;Message- $message\n&quot;;
close(MAIL);

######################################################################
##########################REDIRECT/DON'T EDIT#########################
#Redirect to the Thanks page.
print &quot;Location: $redirect&quot;;

exit;
 
You need to add two \n\n's at the end of it;

e.g

print &quot;Location: $redirect \n\n&quot;;

Also, a side note, you cant use any other content type prints above this (e.g content-type: text/html etc).

Andy
webmaster@ace-installer.com
 
Andy's got it right! You can print either the content-type header OR the location header, but not both. HOWEVER, there is another way to do a redirect, using HTML:
Code:
$url = &quot;[URL unfurl="true"]http://www.somewhere.com/thanks.html&quot;;[/URL]
print <<END_PAGE;
<html>
<head>
<meta http-equiv=&quot;refresh&quot; content=&quot;1;URL=$url&quot;>
<title>REDIRECT</title>
</head>
<body onLoad=&quot;window.location.href='$url';&quot;>
</body>
</html>
END_PAGE
Using the meta tag AND the onload function to redirect may be overkill, but you're pretty much guaranteed that one or the other will work this way, regardless of what browser is being used. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks everyone for all your help! Someone showed me a very small JS snipplet which acts as a redirect very similar to the HTML codes you gave.

Thanks for all your help!

-Acid
 
Additionally you can display a link to the page, if all else fails...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top