Solved

Redirect

Posted on 2000-03-26
8
192 Views
Last Modified: 2010-03-05
Hello,

I have the following script part:

elsif ($r_in->{'action'} eq "write_cart_to_window") {

      require "$datalib/view_cart.pl";
      
      print "\n";

      if ($cart_id && -e "$cart_dir/$cart_id.cart") {
            view_cart(\%in,$cart_id,$r_lang,$r_setup,1);
      }
      else {
            Location: http://mmcw.hypermart.net/cgi-bin/DCShop/menu.html;
      }
}

What I want to do is to redirect to the url http://mmcw.hypermart.net/cgi-bin/DCShop/menu.html when if ($cart_id && -e "$cart_dir/$cart_id.cart") is not true.

The script contains also the line
print "Content-type: text/html\n";
which can not be removed,replaced or changed because the script will then stop workings!!

How to do that??
0
Comment
Question by:mmcw
8 Comments
 
LVL 1

Expert Comment

by:lambda
ID: 2658246
else
{
print "Content-type: text/html\n";
print "Location: http://mmcw.hypermart.net/cgi-bin/DCShop/menu.html\n";
}
0
 
LVL 1

Expert Comment

by:lambda
ID: 2658249
.provided there are no print statements before that.
0
 
LVL 3

Expert Comment

by:jyu_88
ID: 2658607
the 'refesh' meta can work better on som e occasions, like give you a chance to show a page to inform the user they are being redirected and to provide a link to the new location in case the users' browser doesnot take the redirection too well.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 84

Expert Comment

by:ozo
ID: 2658652
If you want to send "Location: http://mmcw.hypermart.net/cgi-bin/DCShop/menu.html\n\n"
you should not send "Content-type: text/html\n\n"
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2658895

from what you are saying there is a common print "Content-type..." statement for both the if and the else part.

what you need to do is put that statement ONLY in the if part (or just before you do a print anywhere else)

when the else part is encountered, the one and only print statement that must be encountered must be the print "Location..." statement.

Alternate if you dont want to or cant remove the print "Content-type:.." statement, replace the print "Location ..." with

print qq{<meta http-equiv="refresh" content="0;
URL=": http://mmcw.hypermart.net/cgi-bin/DCShop/menu.html">
};

Hope that helps..
0
 
LVL 1

Expert Comment

by:lambda
ID: 2659555
But, giving
print "Content-type: text/html\n";
before "Location ..." does work, if there is only one "\n" at its end. I know cos I have tried it.

#!/usr/bin/perl

print "Content-type: text/html\n";
print "Location: http://www.yahoo.com\n";

Maybe it's not needed, but it works.
0
 

Expert Comment

by:moonlx
ID: 2664562
# use the CGI class
use CGI;

#then you can use the following
print $query->redirect("http://mmcw.hypermart.net/cgi-bin/DCShop/menu.html; ")
0
 

Accepted Solution

by:
fatworm earned 50 total points
ID: 2716757
You can't print anything before Location,and the program should be:

else
{
print "Location: http://mmcw.hypermart.net/cgi-bin/DCShop/menu.html\n";
print "Content-type: text/html\n";
}

Maybe can helps...
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

808 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