Solved

Redirect

Posted on 2000-03-26
8
194 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reading fields from the text file. 4 106
Perl string replace for refred url 9 73
How to generate square thumbnail using perl 13 98
read an xml file in perl 2 86
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

751 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