Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

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
0
emma-louise
Asked:
emma-louise
2 Solutions
 
TintinCommented:
Just change the output to be:

print "Location: http://www.somesite.com/page.html\n\n";


Note that the script you are using is very old (last updated in 1994).  I would recommend installing formmail from http://nms-cgi.sourceforge.net/
0
 
manav_mathurCommented:
Tintin, one thing I've noticed is that although what you have said is repeatedly commented in other questions too,
CGI::redirect()

produces a header which contains a STATUS field too. Is that of significance??

Manav
0
 
amc25Commented:
I have used the following code successfully for many times:

use CGI;
$q = new CGI;

print $q->redirect("link/to/page.html");


Make sure that the above redirect-header must be the first output of your script. Otherwise the redirection won't work.

amc25
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ahoffmannCommented:
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)
0
 
xDamoxCommented:
you can also do:

#!/usr/bin/perl -w
#
#

use CGI qw(:standard);

print redirect("www.google.com");

0
 
manav_mathurCommented:
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
   

 
   

0
 
manav_mathurCommented:
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';



0
 
ahoffmannCommented:
Manav, your local ID 13642419 in http:#13643444 is not in this thread, can you please corect
0
 
manav_mathurCommented:
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
0
 
ahoffmannCommented:
<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>
0
 
manav_mathurCommented:
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
0
 
manav_mathurCommented:
>....formmail.pl 'use'ing anywhere
....formail.pl 'use;ing CGI anywhere
0
 
ahoffmannCommented:
at least to valid working suggestions (Tintin, amc25), no reason for a delete
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now