Avatar of shosick
shosick asked on

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

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();

Perl

Avatar of undefined
Last Comment
shosick

8/22/2022 - Mon
rj2

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>");
ASKER
shosick

Yes .. the script you provide works, as well as a couple of other test scripts that I have. Thanks
rj2

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?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
shosick

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';


Tintin

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'
);



ASKER
shosick

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
rj2

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
FishMonger

Could it be that you need:

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

*****
*****

end_base();
$cgi->end_html;
cjmos

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.
Tintin

cjmos.

It doesn't matter if you output multiple HTML files as it isn't related to the original error message.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
cjmos

Tintin,

I got the idea from the following:

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

Figured it was worth a try
ASKER
shosick

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
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
shosick

Thanks for the info! Much appreciated .. I will apply those changes!

Have a good one!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.