Solved

Redirect

Posted on 2000-03-26
8
190 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
Comment Utility
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
Comment Utility
.provided there are no print statements before that.
0
 
LVL 3

Expert Comment

by:jyu_88
Comment Utility
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
 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:maneshr
Comment Utility

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
Comment Utility
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
Comment Utility
# 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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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 …
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 …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now