emma-louise
asked on
Redirect in CGI
I am using the following script to process my email form. However, although it works ok, I don't want to display html thank you's that are inside the script. I want to simply redirect to a thankyou.html page. How can I accomplish this?
http://www.demon.co.uk/tools/formmail/form-mail.pl
Many Thanks
http://www.demon.co.uk/tools/formmail/form-mail.pl
Many Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
print "Location: ..";
as first output should be enough as long as the server is not configured for non-parsing headers (NPH), which is the most common default
using CGI to redirect is overhead (but in this case probably ok, cause CGI is already loaded)
as first output should be enough as long as the server is not configured for non-parsing headers (NPH), which is the most common default
using CGI to redirect is overhead (but in this case probably ok, cause CGI is already loaded)
Interesting,
There was a discussion going on the other day on perlmonks about the usefulness of http:#13642419 over the other method. I specifically stated an example of what has been posted in http:#13642419 . I dont see formmail.pl using CGI anywhere, do we're better of with Tintin's suggestion. However, if you do want to use CGI,
#!/usr/bin/perl -w
use CGI qw/redirect/;
print redirect("www.google.com");
would probably save our namespace a bit. Doesnt count usually, but will matter definitely in case your site hit-rate is good.
Manav
There was a discussion going on the other day on perlmonks about the usefulness of http:#13642419 over the other method. I specifically stated an example of what has been posted in http:#13642419 . I dont see formmail.pl using CGI anywhere, do we're better of with Tintin's suggestion. However, if you do want to use CGI,
#!/usr/bin/perl -w
use CGI qw/redirect/;
print redirect("www.google.com");
would probably save our namespace a bit. Doesnt count usually, but will matter definitely in case your site hit-rate is good.
Manav
However, if you insist on using formmail, this is the modified script
# This should match the mail program on your system.
$mailprog = '/usr/lib/sendmail';
# This should be set to the username or alias that runs your
# WWW server.
$recipient = 'webmaster@your.site.here' ;
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9] )/pack("C" , hex($1))/eg;
# Stop people from using subshells to execute commands
# Not a big deal when using sendmail, but very important
# when using UCB mail (aka mailx).
# $value =~ s/~!/ ~!/g;
# Uncomment for debugging purposes
# print "Setting $name to $value<P>";
$FORM{$name} = $value;
}
# If the comments are blank, then give a "blank form" response
if ($FORM{'comments'}) {
# Now send mail to $recipient
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n";
print MAIL "Subject: WWW comments (Forms submission)\n\n";
print MAIL "$FORM{'username'} ($FORM{'realname'}) sent the following\n";
print MAIL "comment about The Tech's WWW server:\n\n";
print MAIL "------------------------- ---------- ---------- ---------- -----\n";
print MAIL "$FORM{'comments'}";
print MAIL "\n----------------------- ---------- ---------- ---------- -------\n" ;
print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n" ;
print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
close (MAIL);
}
# Print out a redirection header. Change your site HERE
print 'Location: http://www.somesite.com/page.html\n\n';
# This should match the mail program on your system.
$mailprog = '/usr/lib/sendmail';
# This should be set to the username or alias that runs your
# WWW server.
$recipient = 'webmaster@your.site.here'
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9]
# Stop people from using subshells to execute commands
# Not a big deal when using sendmail, but very important
# when using UCB mail (aka mailx).
# $value =~ s/~!/ ~!/g;
# Uncomment for debugging purposes
# print "Setting $name to $value<P>";
$FORM{$name} = $value;
}
# If the comments are blank, then give a "blank form" response
if ($FORM{'comments'}) {
# Now send mail to $recipient
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n";
print MAIL "Subject: WWW comments (Forms submission)\n\n";
print MAIL "$FORM{'username'} ($FORM{'realname'}) sent the following\n";
print MAIL "comment about The Tech's WWW server:\n\n";
print MAIL "-------------------------
print MAIL "$FORM{'comments'}";
print MAIL "\n-----------------------
print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n"
print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
close (MAIL);
}
# Print out a redirection header. Change your site HERE
print 'Location: http://www.somesite.com/page.html\n\n';
Manav, your local ID 13642419 in http:#13643444 is not in this thread, can you please corect
I was referring to xDamox's post. Im still unclear on how you get these ids. Specifically, if you have joined in the thread late and want to know the id for an earlier question.
Manav
Manav
<off-topic>
these IDs are in the HTML source only as a A NAME=, only EE admins, PEs, mods see them in the browser
don't ask me why
Manav, was your reference to http:#13643403 ?
</off-topic>
these IDs are in the HTML source only as a A NAME=, only EE admins, PEs, mods see them in the browser
don't ask me why
Manav, was your reference to http:#13643403 ?
</off-topic>
Yes. My comment was regarding
1) the uselessness of importing all symbols(tagges standard) into the current namespace when only 'redirect' was used.
2) as an implication, why use CGI at all and not go with what Tintin had suggested in the http:#13618236 (hope I get it right this time). I can't see formmail.pl 'use'ing anywhere.
Manav
1) the uselessness of importing all symbols(tagges standard) into the current namespace when only 'redirect' was used.
2) as an implication, why use CGI at all and not go with what Tintin had suggested in the http:#13618236 (hope I get it right this time). I can't see formmail.pl 'use'ing anywhere.
Manav
>....formmail.pl 'use'ing anywhere
....formail.pl 'use;ing CGI anywhere
....formail.pl 'use;ing CGI anywhere
at least to valid working suggestions (Tintin, amc25), no reason for a delete
CGI::redirect()
produces a header which contains a STATUS field too. Is that of significance??
Manav