?
Solved

Redirect in CGI

Posted on 2005-03-23
16
Medium Priority
?
297 Views
Last Modified: 2013-12-25
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
Comment
Question by:emma-louise
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
16 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 252 total points
ID: 13618236
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
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13620361
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
 

Assisted Solution

by:amc25
amc25 earned 248 total points
ID: 13640992
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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 51

Expert Comment

by:ahoffmann
ID: 13642328
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
 
LVL 16

Expert Comment

by:xDamox
ID: 13643403
you can also do:

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

use CGI qw(:standard);

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

0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13643444
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
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13643483
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13646663
Manav, your local ID 13642419 in http:#13643444 is not in this thread, can you please corect
0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13650062
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13650213
<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
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13650379
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
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13650386
>....formmail.pl 'use'ing anywhere
....formail.pl 'use;ing CGI anywhere
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13954308
at least to valid working suggestions (Tintin, amc25), no reason for a delete
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question