Solved

CGI Error - HTTP Headers - Script Works on Earthlink Hosted Site -- Not On IIS 5.0 or 6.0 site

Posted on 2004-03-24
16
462 Views
Last Modified: 2008-02-26
Hello,

I am moving a website from an Earthlink hosted environment to an IIS environment. The script works fine in the Earthlink hosted environment. I have installed ActivePerl 5.8 on the IIS 5.0 and 6.0 machines and have created a "test" perl script, dropped it in the CGI folder that I have created, ensuring that Perl is working correctly. All files are present as they are currently on the Earthlink site and listed in the script. However, in IIS 5.0 I get the following error:

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

in IIS 6.0 I get the following error:

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

It is all blank after the error message. No clues as to the issue.

Here is my script. Any thoughts? Thanks a ton!

*********************************************************

#!/usr/local/bin/perl

BEGIN {
open (STDERR, ">../lo") || die "Cannot redirect STDERR: $!";
} #Open log file for appending

use CGI;
use CGI qw(:standard :html3);
$cgi = new CGI;
#--------------------
# configuration
#--------------------
$this_url = 'http://www.192.168.1.104.com/cgi/store_locator.pl';
#--------------------
# end configuration
#--------------------

$| = 1;
$first_half = 'header.htm';
$second_half = 'footer.htm';
$warehouses = 'warehouses.txt';
$stores = 'stores.txt';

$state_hash{AK} = 'Alaska';
$state_hash{AL} = 'Alabama';
$state_hash{AR} = 'Arkansas';
$state_hash{AZ} = 'Arizona';
$state_hash{CA} = 'California';
$state_hash{CO} = 'Colorado';
$state_hash{CT} = 'Connecticut';
$state_hash{DE} = 'Delaware';
$state_hash{FL} = 'Florida';
$state_hash{GA} = 'Georgia';
$state_hash{HI} = 'Hawaii';
$state_hash{IA} = 'Iowa';
$state_hash{ID} = 'Idaho';
$state_hash{IL} = 'Illinois';
$state_hash{IN} = 'Indiana';
$state_hash{KS} = 'Kansas';
$state_hash{KY} = 'Kentucky';
$state_hash{LA} = 'Louisiana';
$state_hash{MA} = 'Massachusetts';
$state_hash{MD} = 'Maryland';
$state_hash{ME} = 'Maine';
$state_hash{MI} = 'Michigan';
$state_hash{MN} = 'Minnesota';
$state_hash{MO} = 'Missouri';
$state_hash{MS} = 'Mississippi';
$state_hash{MT} = 'Montana';
$state_hash{NC} = 'North Carolina';
$state_hash{ND} = 'North Dakota';
$state_hash{NE} = 'Nebraska';
$state_hash{NH} = 'New Hampshire';
$state_hash{NJ} = 'New Jersey';
$state_hash{NM} = 'New Mexico';
$state_hash{NV} = 'Nevada';
$state_hash{NY} = 'New York';
$state_hash{OH} = 'Ohio';
$state_hash{OK} = 'Oklahoma';
$state_hash{OR} = 'Oregon';
$state_hash{PA} = 'Pennsylvania';
$state_hash{RI} = 'Rhode Island';
$state_hash{SC} = 'South Carolina';
$state_hash{SD} = 'South Dakota';
$state_hash{TN} = 'Tennessee';
$state_hash{TX} = 'Texas';
$state_hash{UT} = 'Utah';
$state_hash{VA} = 'Virginia';
$state_hash{VT} = 'Vermont';
$state_hash{WA} = 'Washington';
$state_hash{WI} = 'Wisconsin';
$state_hash{WV} = 'West Virginia';
$state_hash{WY} = 'Wyoming';


#----------------------
# start_base()
#----------------------
sub start_base {
$first_half_content = '';
open(FH, "$warehouses") || die "could not open $warehouses";
LINE: while (<FH>) {
            my ( $t_code, $t_description, $t_warehouse, $t_cust_sku, $t_link ) = split( /\t/, $_ );
            if ($t_code eq $code) {
                  $title = 'Store Locations For ' . $t_description;
                  last LINE;
            }
      }
close FH;            
      
      
      open(FH, "$first_half") || die "could not open $first_half";
      while (<FH>) {
            $first_half_content .= $_;
      }
close FH;
$first_half_content =~ s/<title><\/title>/<title>$title<\/title>/m;
print $first_half_content;
}
#----------------------
# end_base()
#----------------------
sub end_base {
print qq(<br><BR><font size=2><a href="http://192.168.1.104/faqs.htm">What should I do if a store is not listed by or near the city or state where I am trying to locate your product in?</a></font><p></p>);

      open(FH, "$second_half") || die "could not open $second_half";
      while (<FH>) {
            print $_;
      }
close FH;
}
#----------------------
# display_warehouses()
#----------------------
sub display_warehouses {
      my $state_counter = 0;
      open(FH, "$stores") || die "could not open $stores";
      while (<FH>) {
                        ( $t_code, $t_product_name, $t_customer_name, $t_address, $t_city, $t_state, $t_zip, $t_phone ) = split( /\t/, $_ );
            if ($t_code eq $code) {
                  push @thestates, $t_state;
                  $the_product = $t_product_name;
            } #if $t_code eq $code
      } #while
      close FH;

      %seen = ();
      foreach $item (@thestates) {
          $seen{$item}++;
      }
      @uniq_states = keys %seen;
      @uniq_states = sort @uniq_states;


      foreach $u_state (@uniq_states) {
            $state_counter++;
      }
      $half_states = $state_counter / 2;
      $half_states = sprintf("%0.0f", $half_states);
      print "<font color=#FF0000><b><i>$the_product</i></b></font><br><p></p>";

      if ($state eq 'all') {
            $first_part_wh = '<table align=center width=100%><tr><td><font size=2>Below is a list of major warehouses or stores that may carry this product. Stores marked with an asterisk (*) means that they may only sell in certain areas. The list below will link you to the web site\'s Store Locator where you can search for a store near you and then <b>call and find out if they have this item in stock.</b></font><p><ul>';            
      } else {
            $first_part_wh = '<table align=center width=100%><tr><td><font size=2>Below is a list of major warehouses or stores that may carry this product. Stores marked with an asterisk (*) means that they may only sell in certain areas. The list below will link you to the web site\'s Store Locator where you can search for a store near you and then <b>call and find out if they have this item in stock.</b></font><p><ul>';
      }
      open(FH, "$warehouses") || die "could not open $warehouses";
      $warehouse_counter = 0;

      while (<FH>) {
            my ( $t_code, $t_description, $t_warehouse, $t_cust_sku, $t_link ) = split( /\t/, $_ );
            if ($t_code eq $code) {
                  if ($warehouse_counter == 0) {
                        print $first_part_wh;
                  }

                  print "<li><a href=$t_link><font size=2>$t_warehouse</font></a>\n";
                  if ($t_cust_sku) {
                        $t_cust_sku =~ s/"//g;
                        print "<font size=2> (SKU # $t_cust_sku )</font>\n";
                  }
                  $warehouse_counter++;
            } # if $t_code eq $code
      }
      if ($warehouse_counter > 0) {
            print '</ul></td></tr></table>';
      }

      close FH;
}


#----------------------
# display_stores()
#----------------------
sub display_stores {
      if ($warehouse_counter > 0) {
            $call_local_store = '<p align=left><font size=2 color=FF0000>NOTE: Product sizes available may vary by store.</font></p>';      
      } else {
      $call_local_store = '';
      }

      open(FH, "$stores") || die "could not open $stores";
      $store_counter = 0;
      while (<FH>) {
            my ( $t_code, $t_product_name, $t_customer_name, $t_address, $t_city, $t_state, $t_zip, $t_phone ) = split( /\t/, $_ );
            $t_customer_name =~ s/"//g;
            $t_address =~ s/"//g;
            $first_part_st = "$call_local_store <br><font size=2 color=#FF0000><b><i>
              $t_product_name";
            if ($state) {
                  if (exists $state_hash{$state}) {
                        $first_part_st .= " in $state_hash{$state}<p></p>\n";
                  } else {
                        $first_part_st .= " in $state<p></p>\n";
                  }
            }
            $first_part_st .= '</i></b></font>';
            $first_part_st .= '<br><center><table align=center border=1 width=100%>';

            $first_part_st .= "<tr><td><font size=2><B><a href=\"$this_url?sort=2&code=$code&state=$state\">CUSTOMER NAME</a></B></font></td><td><font size=2><B><a href=\"$this_url?sort=3&code=$code&state=$state\">ADDRESS</a></B></font></td><td><font size=2><B><a href=\"$this_url?sort=0&code=$code&state=$state\">CITY</a></B></font></td><td><font size=2><B><a href=\"$this_url?sort=1&code=$code&state=$state\">STATE</a></B></font></td><td><font size=2><B><a href=\"$this_url?sort=4&code=$code&state=$state\">ZIP</B></font></td><td><font size=2><B><a href=\"$this_url?sort=5&code=$code&state=$state\">TELEPHONE</a></B></font></td></tr>\n";

            if (($t_code eq $code) && ($state eq $t_state || ! $state  ) ) {
                  if ($store_counter == 0) {
                        print $first_part_st;
                  }
                  push (@cityary, "$t_city|$t_state|$t_customer_name|$t_address|$t_zip|$t_phone");

                  $store_counter++;
            }
      }

unless ($sort){ $sort=0; }

   foreach (@cityary) { $sort_field{$_} = (split(/\|/, $_))[$sort];   }#, 5
   @sorted = sort { $sort_field{$a} cmp $sort_field{$b} } @cityary; @sortedcityary = @sorted;

      foreach $tableline (@sortedcityary) { ($t_city,$t_state,$t_customer_name,$t_address,$t_zip,$t_phone)=split(/\|/, $tableline);

print "<tr><td class=tb>$t_customer_name</td><td class=tb>$t_address</td><td class=tb>$t_city</td><td class=tb>$t_state</td><td class=tb>$t_zip</td><td class=tb>$t_phone</td></tr>\n";

      }


      if ($store_counter > 0) {
            print '</table></center>';
      }

close FH;
}

#----------------------
# display_all
#----------------------
sub display_all {
print "<table align=center border=1 width=96%>";
      open(FH, "$stores") || die "could not open $stores";
      while (<FH>) {
      ( $t_code, $t_product_name, $t_customer_name, $t_address, $t_city, $t_state, $t_zip, $t_phone ) = split( /\t/, $_ );
if ($t_code ne $lastcode) {
@list=sort (@lists);
      foreach $list (@list) { ( $state, $hcode, $product_name, $customer_name,$city ) = split(/\|/, $list);
print "<tr><td class=tb>$city</td><td class=tb>$state</td><td class=tb>$customer_name</td></tr>\n";  }

print "<tr><td class=tb>$t_code $t_product_name</td><td class=tb colspan=2>&nbsp;</td></tr>\n";  @lists=""; @list=""; $list="";
 } else { push (@lists, "$t_state|$t_code|$t_product_name|$t_customer_name|$t_city"); }
$lastcode=$t_code;
}
print "</table>"; }

#----------------------
# display_states()
#----------------------
sub display_states {
      my $state_counter = 0;
      open(FH, "$stores") || die "could not open $stores";
      while (<FH>) {
                        ( $t_code, $t_product_name, $t_customer_name, $t_address, $t_city, $t_state, $t_zip, $t_phone ) = split( /\t/, $_ );
            if ($t_code eq $code) {
                  push @thestates, $t_state;
                  $the_product = $t_product_name;
            } #if $t_code eq $code
      } #while
      close FH;

      %seen = ();
      foreach $item (@thestates) {
          $seen{$item}++;
      }
      @uniq_states = keys %seen;
      @uniq_states = sort @uniq_states;


      foreach $u_state (@uniq_states) {
            $state_counter++;
      }
      $half_states = $state_counter / 2;
      $half_states = sprintf("%0.0f", $half_states);
      print "<p align=left><font size=2>Click on the Links below that are separated by state to see store location information that carry $the_product.</font><br><font color=#FF0000 size=2>NOTE: Product sizes may vary by store.</font></p>";
            
      print "<table width=100%><tr><td>";
      print "<ul>";
      $counter = 0;
      foreach $u_state (@uniq_states) {
            #print "<li>$u_state";
            if (exists $state_hash{$u_state}) {
                  print "<li><a href=$this_url?sort=2&code=$code&state=$u_state>$state_hash{$u_state}</a>\n";
            } else {
                  print "<li><a href=$this_url?sort=2&code=$code&state=$u_state>$u_state</a>\n";
            }
            $counter++;
            if ($counter == $half_states) {
                  print "</td><td>";
            }      
      }
      print "</ul></td></tr></table></center>";

}
#----------------------
# main()
#----------------------

$code = $cgi->param("code");
$state = $cgi->param("state");
$sort = $cgi->param("sort");

print $cgi->header();
start_base();
if (! $code) {
      print 'Error: no parameters were recognized.  Please double-check the url';
} else {
      if (! $state) {
            # only parameter is code
            # show for all states
            display_warehouses();
            display_stores();
      }
elsif ( $state eq 'all' && $code eq 'all') {
            display_all(); exit;

      }      
 elsif ( $state eq 'all' ) {
            # params: code, state
            # display page listing the states                  
            display_warehouses();
            display_states();
      }  else {
            # params: code, state
            # show for particular state
            #display_warehouses();
            display_stores();
      } #if ! state}#if ! code



end_base();

0
Comment
Question by:shosick
[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
  • 5
  • 3
  • 3
  • +2
16 Comments
 
LVL 10

Expert Comment

by:rj2
ID: 10671309
Does the script below work?
If not there is a problem with the environment and not with your script.

print "Content-Type: text/html\n\n";      
print("<HTML><BODY>test</BODY></HTML>");
0
 

Author Comment

by:shosick
ID: 10671408
Yes .. the script you provide works, as well as a couple of other test scripts that I have. Thanks
0
 
LVL 10

Expert Comment

by:rj2
ID: 10671519
Try to use a full path for line below.
$warehouses = 'warehouses.txt';

change to e.g.
$warehouses = 'c:/inetpub/wwwroot/mysite/warehouses.txt';

Does that help any?
0
Independent Software Vendors: 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!

 

Author Comment

by:shosick
ID: 10672008
No suck luck. Here were the changes I made: Thanks again!

***************************************************

BEGIN {
open (STDERR, ">C:/Inetpub/wwwroot/jasco/cgi/errors/lo") || die "Cannot redirect STDERR: $!";
} #Open log file for appending

use CGI;
use CGI qw(:standard :html3);
$cgi = new CGI;
#--------------------
# configuration
#--------------------
$this_url = 'http://192.168.1.104/jasco/cgi/store_locator.pl';
#--------------------
# end configuration
#--------------------

$| = 1;
$first_half = 'C:/Inetpub/wwwroot/jasco/cgi/header.htm';
$second_half = 'C:/Inetpub/wwwroot/jasco/cgi/footer.htm';
$warehouses = 'C:/Inetpub/wwwroot/jasco/cgi/warehouses.txt';
$stores = 'C:/Inetpub/wwwroot/jasco/cgi/stores.txt';


0
 
LVL 48

Expert Comment

by:Tintin
ID: 10672217
It doesn't help that you are mixing up the two CGI interfaces (OO and function).  You should use one or the other.  So in your case, remove the line:


use CGI qw(:standard :html3);

On an unrelated matter, your state hash:

$state_hash{AK} = 'Alaska';
$state_hash{AL} = 'Alabama';
$state_hash{AR} = 'Arkansas';
$state_hash{AZ} = 'Arizona';

is more commonly written as:

%state_hash = (
  AK => 'Alaska',
  AL => 'Alabama',
  AR => 'Arkansas'
);



0
 

Author Comment

by:shosick
ID: 10672358
Thanks ... made both suggested changes. Still no luck. New changes continue to work on live earthlink site, but no luck with IIS 5.0 or 6.0 .. Steve
0
 
LVL 10

Accepted Solution

by:
rj2 earned 250 total points
ID: 10672378
Does problem remain if you comment out the line "open (STDERR,..." ?
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 10672387
Could it be that you need:

$cgi->header();
$cgi->start_html();

*****
*****

end_base();
$cgi->end_html;
0
 
LVL 3

Expert Comment

by:cjmos
ID: 10672484
Hi,

It looks to me like you're printing multiple page headers,

you've got

open(FH, "$first_half") || die "could not open $first_half";
     while (<FH>) {
          $first_half_content .= $_;
     }
close FH;
print $first_half_content;

and then

     open(FH, "$second_half") || die "could not open $second_half";
     while (<FH>) {
          print $_;
     }


I presume $first_half (being a .htm page with title tags includes headers so now you've got 2 sets of <html><head></head> etc...

show me the contents of header.htm and footer.htm (feel free to exclude data for security reason) and i'll think of a way round this for you.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10672612
cjmos.

It doesn't matter if you output multiple HTML files as it isn't related to the original error message.
0
 
LVL 3

Expert Comment

by:cjmos
ID: 10672709
Tintin,

I got the idea from the following:

http://www.faqts.com/knowledge_base/view.phtml/aid/2129

Figured it was worth a try
0
 

Author Comment

by:shosick
ID: 10672851
Ladies or Gentleman,

Thank you all for your assistance! I was able to fix the issue with a combination of your efforts/suggestions. The last thing that did is was to comment out the following and add a "}" (w/o the ") to the end of the script:

#BEGIN {
#open (STDERR, ">C:/Inetpub/wwwroot/jasco/cgi/errors/lo") || die "Cannot redirect STDERR: $!";
#} #Open log file for appending

Thanks again all and have a good day! ... Steve
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 250 total points
ID: 10673049
Normallly, if you want to see any errors in a Perl/CGI script, you add:

use CGI::Carp qw(fatalsToBrowser);


The CGI::Carp module can also redirect to a specified file.
0
 

Author Comment

by:shosick
ID: 10673166
Thanks for the info! Much appreciated .. I will apply those changes!

Have a good one!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…

739 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