troubleshooting Question

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

Avatar of shosick
shosick asked on
Perl
14 Comments2 Solutions510 ViewsLast Modified:
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();

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 14 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros