Solved

Redirect

Posted on 2000-03-26
8
195 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
[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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Six Sigma Control Plans

623 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