By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,541 Members | 1,476 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,541 IT Pros & Developers. It's quick & easy.

CGI header problem

rajiv07
100+
P: 141
Hi to all

I have a script to get geo IP which is successfully running on Linux server.but when i run this script on windows server it gives some header error

Expand|Select|Wrap|Line Numbers
  1. #!C:/Perl/bin/perl.exe
  2. use CGI qw/:standard/;
  3. use LWP::UserAgent;
  4. use HTTP::Request qw(GET POST);
  5. use HTTP::Headers;
  6.  
  7. use CGI::Cookie;
  8. use CGI::Session;
  9.  
  10. use CGI::Carp qw(fatalsToBrowser);
  11.  
  12. my $q=new CGI;
  13.  
  14. my $c=new CGI::Cookie;
  15.  
  16. my $cIP = $ENV{'REMOTE_ADDR'} ;
  17.  
  18. # replace this value with license key
  19. my $license_key ="key";
  20.  
  21.  
  22. my $ua = LWP::UserAgent->new(timeout =>10);
  23.  
  24. my $h = HTTP::Headers->new;
  25.  
  26. $h->content_type('application/x-www-form-urlencoded');
  27.  
  28. my $request = HTTP::Request->new('POST','http://maxmind.com:8010/a',
  29.                                  $h,"l=$license_key&i=$cIP");
  30. my $res = $ua->request($request);
  31.  
  32. my $content = $res->content;
  33. #print "Content-type: text/html\n\n" ;
  34. ############ again send request    #######
  35. if($content eq "")
  36. {
  37.  sleep(1);
  38.  
  39.  $request = HTTP::Request->new('POST','http://maxmind.com:8010/a', 
  40.                                $h,"l=$license_key&i=$cIP");        
  41.  $res = $ua->request($request);                                    
  42.  
  43.  $content = $res->content;                                         
  44. }
  45. if($content eq "")
  46. {
  47.  sleep(1);
  48.  
  49.  $request = HTTP::Request->new('POST','http://maxmind.com:8010/a', 
  50.                                $h,"l=$license_key&i=$cIP");        
  51.  $res = $ua->request($request);                                    
  52.  
  53.  $content = $res->content;                                         
  54. }
  55. if($content eq "")
  56. {
  57.     $content="Server-Error";
  58. }
  59.  
  60. my $session = "" ;
  61.  
  62. my $sid = "" ;
  63.  
  64. $sid = _Checkcookie();
  65.  
  66. if($sid eq "")
  67. {
  68.  $session = new CGI::Session("driver:File", $q, {Directory=>'/tmp'});
  69.  
  70.  my $server = $ENV{'HTTP_HOST'};
  71.  
  72.  my $path = "/";
  73.  
  74.  $sid = $session->id();
  75.  
  76.  print "Set-Cookie: CGISESSID\=$sid; path\=$path;domain\=$server\n" ;
  77. }
  78. else
  79. {
  80.  $session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
  81. }
  82.  
  83. my $cFlag = 0 ;
  84.  
  85. my $referer=$q->param('referer');
  86.  
  87. my $albumid=$q->param('albumid');
  88.  
  89. my $action=$q->param('action');
  90.  
  91. my $shopping_info=$session->param('shopping_info');
  92.  
  93. my %shopping_info=%{$shopping_info};
  94.  
  95. $shopping_info{geo}=$content; 
  96.  
  97.  
  98. $session->param("shopping_info",\%shopping_info);
  99.  
  100. $session->expire('+12h');
  101.  
  102. if($action eq "direct"){
  103. #print "location: /cgi-bin/elearning/query/el_alb_details.pl?albumid=$albumid&action=geo\n\n" ;
  104. print "Status: 302 Moved", "\r\n","Location: http://www.mysitename.com/cgi-bin/elearning/query/el_alb_details.pl?albumid=$albumid&action=geo", "\r\n\r\n";
  105. exit;
  106. }
  107.  
  108. print 'Status: 302 Moved', "\r\n",'Location:/cgi-bin/elearning/query/el_show_cat.pl', "\r\n\r\n"; 
  109.  
  110. exit;
  111.  
  112. sub _Checkcookie{
  113.  
  114. my %cookies=fetch CGI::Cookie;
  115.  
  116. my $name=$cookies{CGISESSID};
  117.  
  118. my @temp=split(/CGISESSID\=/,$name);
  119.  
  120. my @temp1=split(/;/,$temp[1]);
  121.  
  122. return $temp1[0];
  123. }
My error

The specified CGI application misbehaved by not returning a complete set of HTTP headers.

Please help on this

Thanks in advance
Rajiv
Jun 18 '08 #1
Share this Question
Share on Google+
2 Replies


KevinADC
Expert 2.5K+
P: 4,059
for now do this, change these lines:

Expand|Select|Wrap|Line Numbers
  1. print 'Status: 302 Moved', "\r\n",'Location:/cgi-bin/elearning/query/el_show_cat.pl', "\r\n\r\n";
to:

Expand|Select|Wrap|Line Numbers
  1. print 'Location: http://www.yoursite.com/cgi-bin/elearning/query/el_show_cat.pl', "\r\n\r\n";
and see if that gets the script running. If it does, the problem is in the header your script is printing. If not, I don't know what the problem is.
Jun 18 '08 #2

rajiv07
100+
P: 141
Thanks Kevin,

Actually i am trying to move all script from Linux Server to windows server.No program is work.All script gives the same error.i could not find any problem.But when i run a simple test script its working fine.

My testing script

Expand|Select|Wrap|Line Numbers
  1. #!C:/perl/bin/perl.exe
  2. use CGI qw/:standard/;
  3.  
  4. use CGI::Carp qw(fatalsToBrowser);
  5.  
  6. my $q=new CGI;
  7.  
  8. my $cFlag = 0 ;
  9.  
  10. my $referer=$q->param('referer');
  11.  
  12. my $albumid=$q->param('albumid');
  13.  
  14. my $action=$q->param('action');
  15.  
  16. print $q->header;
  17.  
  18. print "Hello world";
  19.  
  20. exit;
  21.  
  22.  
Is any server configuration fault has involved in this problem.

Plesae suggest me any idea or solution please.

Thanks in advance

Rajiv
Jun 19 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.