1

I have created a file called "nph-select.pl" and put code for redirection as below.

#!"D:\xampp\perl\bin\perl.exe" -w
use CGI qw/:standard/; 
my $cgi = new CGI; 
print $cgi->redirect(-uri => 'http://www.google.com/', -nph => 1); 

and executing file then its gives me 302 STATUS message saying "Document has moved here" . But when I am renaming the same file just by removing "-" in it i.e new file name is "nphselect.pl" then it run properly with redirection also. Can anybody suggect what setting I am missing?

My request headers are Host localhost:8080 User-Agent Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 Accept text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language en-us,en;q=0.5 Accept-Encoding gzip, deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 115 Connection keep-alive

And RESPONSE HEADERS are blank.

Rahul
  • 55
  • 1
  • 1
  • 5

1 Answers1

6

First, some webservers treat cgi scripts starting 'nph-' differently than any other cgi script, so removing the - will change that.

You are calling redirect incorrectly; CGI's named parameters all must start with -, like this:

print $cgi->redirect(-uri => 'http://perl.about.com/'); 

With uri instead of -uri, it is using positional parameters, so it tries to redirect to 'url' (which your webserver may fully qualify for you).

If you are going to use an nph- script, setting redirect's nph option provides a fuller set of headers; this may resolve your problem:

print $cgi->redirect(-uri => 'http://perl.about.com/', -nph => 1); 
ysth
  • 96,171
  • 6
  • 121
  • 214
  • Now i am getting "Internet Explorer cannot display the webpage" error. – Rahul Jul 06 '11 at 08:30
  • @Rahul: in your question, please show your complete current code and say what the filename is and what webserver you are running. – ysth Jul 06 '11 at 08:31
  • I have pasted the current code in my question. and added the "-nph=>1" . – Rahul Jul 06 '11 at 08:45
  • Following is the code and I am running on xampp. #!"D:\xampp\perl\bin\perl.exe" -w use CGI qw/:standard/; my $cgi = new CGI; print $cgi->redirect(-uri => "http://perl.about.com/", -nph => 1); – Rahul Jul 06 '11 at 08:58
  • You're going to have to use something that shows you the actual response from your server to get any further, for instance, `curl -v your-url` – ysth Jul 06 '11 at 16:55
  • I am not getting what you said. – Rahul Jul 07 '11 at 05:20
  • Your browser is hiding from you what is actually coming from the server (that it finds objectionable). There are many ways to get past this: using curl, or firefox+firebug's net tab, or the equivalent feature of chrome are three. – ysth Jul 07 '11 at 06:24
  • But when I am running files without "nph-" then those are running fine. I am running site on IE browser. My Apachee version is 2.2.10. I think there is probles with nph headers in apachee 2.2 – Rahul Jul 07 '11 at 07:44
  • So figure out what the problem is as I suggested? – ysth Jul 07 '11 at 08:01
  • I have to pass Full headers with redirect. but how to do that in PERL ? I dont have any knowledge of PERL. Can you please let me know how to pass full header in PERL? – Rahul Jul 07 '11 at 08:27
  • the -nph option is supposed to do that. when I try it, it appears to. post your current code in your question (not in a comment where it isn't formatted readably), and show what your server is actually outputing (using one of the ways I suggested). – ysth Jul 07 '11 at 08:39
  • My request Headers are: Host localhost:8080 User-Agent Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language en-us,en;q=0.5 Accept-Encoding gzip, deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 115 Connection keep-alive AND RESPONSE Headers are blank – Rahul Jul 07 '11 at 08:44
  • Problem resolved . by adding a line abode redirect() line. Added Line: print "Content-type: text/html\n\n"; – Rahul Jul 07 '11 at 09:40