Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Redirect

Posted on 2000-03-26
8
Medium Priority
?
197 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 85

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 150 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Six Sigma Control Plans

886 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