SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Iceman90's Avatar
    Join Date
    Mar 2006
    Location
    Calgary, Alberta, Canada
    Posts
    392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Perl Scripting Help - Premature end of script headers

    Hello,

    I've never written a line of Pearl in my life, but I am currently working on a site that runs a legacy Pearl script. I just moved this site to a new host, and now the CGI file doesn't work. I have the following error message in my server logs:

    [Thu Mar 12 16:53:21 2009] [error] [client 216.110.94.227] Premature end of script headers: chart.cgi, referer: http://www.connectrafusion.com/fusion-calculator.php

    I was wondering if anyone could help me figure this issue out. Below is the code I am dealing with:

    Code Perl:
    #!/usr/bin/perl
    use POSIX;
     
    &GetFormInput;
     
    $ftype=$field{'ftype'};
    $pressure=$field{'pressure'};
    $pipestyle=$field{'pipestyle'};
    $dopf=$field{'dopf'};
     
    print "Content-type: text/html\n\n";
    if (!$dopf){
    	open (FILE,"<header2.txt");
    	foreach (<FILE>){ print $_; }
    	close (FILE);
    } else {
    	print "<html><head><title>Connectra Fusion Pressure Charts</title></head><body bgcolor=#ffffff>";
    }
    if (!$ftype || !$pressure || !$pipestyle) {
     
    print<<EOM;
    <form action=chart.cgi method=post>
    <table width=100%><tr><td><center><font size=2 face=verdana><b>Select Pipe Type, Machine Type, and Interfacial Pressure</b><br><br>
    <table><tr><td><font size=2 face=verdana>Pipe Type</td><td><select name=pipestyle style='width:200px'>
    <option value="dips">DIPS</option>
    <option value="ips">IPS</option>
    </select>
    </td></tr>
    <tr><td><font size=2 face=verdana>Machine Type</td><td>
    <select style='width:200px' name=ftype>
    <option value="28HP">28 HP (820 HP)
    <option value="28 EP (CF-28)">28 EP (CentreFuseŽ 28)
    <option value="28 GS">28 GS
    <option value="28 CQ(a)">28 CQ (820 CQ)
    <option value="28 IP">28 IP (28 CQIP)
    <option value="314 HP">314 HP (1420 HP)
    <option value="314 EP">314 EP (1420 EP)
    <option value="314 CQ">314 CQ (1420 CQ)
    <!--<option value="618 EP">618 EP Machine-->
    <option value="620 SC">620 SC (CentreFuseŽ 618)
    <option value="824 EP">824 EP (2440 EP)
    <option value="1442 EP">1442 EP (1442)
    </select>
    </td></tr>
    <tr><td><font size=2 face=verdana>Interfacial Pressure:</td><td><input type=text name=pressure style='width:200px'>
    </td></tr>
    <tr><td colspan=2 align=center><input type=submit value=Calculate></td></tr></table>
     
    EOM
    } else {
    if ($ftype eq "28HP"){ $title="28 HP (820 HP)";}
    if ($ftype eq "28 EP (CF-28)"){	$title="8 EP (CentreFuseŽ 28)";}
    if ($ftype eq "28 GS"){	$title="28 GS";}
    if ($ftype eq "28 CQ(a)"){ $title="28 CQ (820 CQ)";}
    if ($ftype eq "28 IP"){	$title="28 IP Butt Fusion";}
    if ($ftype eq "314 HP"){ $title="314 HP (1420 HP)";}
    if ($ftype eq "314 EP"){ $title="314 EP (1420 EP)";}
    if ($ftype eq "314 CQ"){ $title="314 CQ (1420 CQ)";}
    if ($ftype eq "618 EP"){ $title="618 EP Machine";}
    if ($ftype eq "620 SC"){ $title="620 SC (CentreFuseŽ 618)";}
    if ($ftype eq "824 EP"){ $title="824 EP (2440 EP)";}
    if ($ftype eq "1442 EP"){ $title="1442 EP (1442)";}
     
    if (($ftype eq "28HP") || ($ftype eq "28 EP (CF-28)") || ($ftype eq "28 GS") || ($ftype eq "28 CQ(a)") || ($ftype eq "28 IP")){
    	if ($pipestyle eq "ips"){
    		@nominal = (2,3,4,5,5,6,7,8);
    		@actual = (2.375,3.5,4.5,5.375,5.563,6.625,7.125,8.625);
    		if ($ftype eq "28HP"){
    			$ceca = 1.964;
    		}
    		if ($ftype eq "28 EP (CF-28)"){
    			$ceca = 4.712;
    		}
    		if ($ftype eq "28 GS"){
    			$ceca = 3.24;
    		}
    		if ($ftype eq "28 CQ(a)"){
    			$ceca = 1.964;
    		}
    		if ($ftype eq "28 IP"){
    			$ceca = 2.651;
    		}
    	} else {
    		@nominal = (4,6,8);
    		@actual = (4.8,6.9,9.05);
    		if ($ftype eq "28HP"){
    			$ceca = 1.964;
    		}
    		if ($ftype eq "28 EP (CF-28)"){
    			$ceca = 4.712;
    		}
    		if ($ftype eq "28 GS"){
    			$ceca = 3.24;
    		}
    		if ($ftype eq "28 CQ(a)"){
    			$ceca = 1.964;
    		}
    		if ($ftype eq "28 IP"){
    			$ceca = 2.651;
    		}
    	}
    }
    if (($ftype eq "314 HP") || ($ftype eq "314 EP") || ($ftype eq "314 CQ")){
    	if ($pipestyle eq "ips"){
    		@nominal = (3,4,5,5,6,7,8,10,12,14);
    		@actual = (3.5,4.5,5.375,5.563,6.625,7.125,8.625,10.75,12.75,14);
    		if ($ftype eq "314 HP"){
    			$ceca = 1.964;
    			$mnote = "<center><b>NOTE:  Pump is rated for a maximum of 1500 psi gauge. </b><br><br></center>";
    		}
    		if ($ftype eq "314 EP"){
    			$ceca = 4.712;
    		}
    		if ($ftype eq "314 CQ"){
    			$ceca = 2.651;
    			$mnote = "<center><b>NOTE:  Pump is rated for a maximum of 1500 psi gauge. </b><br><br></center>";
    		}
    	}
    	if ($pipestyle eq "dips"){
    		@nominal = (4,6,8,10,12);
    		@actual = (4.8,6.9,9.05,11.1,13.2);
    		if ($ftype eq "314 HP"){
    			$ceca = 1.964;
    			$mnote = "<center><b>NOTE:  Pump is rated for a maximum of 1500 psi gauge. </b><br><br></center>";
    		}
    		if ($ftype eq "314 EP"){
    			$ceca = 4.712;
    		}
    		if ($ftype eq "314 CQ"){
    			$ceca = 2.651;
    			$mnote = "<center><b>NOTE:  Pump is rated for a maximum of 1500 psi gauge. </b><br><br></center>";
    		}
    	}
    }
    if (($ftype eq "618 EP") || ($ftype eq "620 SC")){
    	if ($pipestyle eq "dips"){
    		@nominal = (6,8,10,12,16,18);
    		@actual = (6.9,9.05,11.1,13.2,17.4,19.5);
    		if ($ftype eq "618 EP"){
    			$ceca = 3.559;
    		} else {
    			$ceca = 7.854;
    		}
    	}
    	if ($pipestyle eq "ips"){
    		@nominal = (6,8,10,12,14,16,18,20);
    		@actual = (6.625,8.625,10.75,12.75,14,16,18,20);
    		if ($ftype eq "618 EP"){
    			$ceca = 3.559;
    		} else {
    			$ceca = 7.854;
    		}
    	}
     
    }
    if ($ftype eq "824 EP"){
    	if ($pipestyle eq "ips"){
    		@nominal = (8,10,12,14,16,18,20,22,24);
    		@actual = (8.625,10.750,12.75,14,16,18,20,22,24);
    		$ceca=6.283;
    	} else {
    		@nominal = (8,10,12,16,18,20,24);
    		@actual = (9.05,11.1,13.2,17.4,19.5,21.6,25.8);
    		$ceca = 6.283;
    	}
    }
    if ($ftype eq "1442 EP"){
    	if ($pipestyle eq "dips"){
    		@nominal = (16,18,20,24,30,36);
    		@actual = (17.4,19.5,21.6,25.8,32,38.3);
    	} else {
    		@nominal = (14,16,18,20,22,24,26,28,30,32,34,36,42);
    		@actual = (14,16,18,20,22,24,26,28,30,32,34,36,42);
    	}
    	$ceca = 20.028;
    }
    @sdr = (7,7.3,9,9.3,11,11.5,13.5,15.5,17,21,26,32.5);
    if (!$dopf){
    	print "<i><a href='chart.cgi?ftype=$ftype&pressure=$pressure&pipestyle=$pipestyle&dopf=1' target=_new>Printer-Friendly Version</a></i><br><br>";
    }
    print "<center><font size=2 face=verdana><b>Connectra Fusion</b><br>Butt Fusion Gauge Pressures<br>$title - $ceca sq. in. CECA<br><br></font></center><i><font size=\"3\" face=\"Arial, Helvetica, sans-serif\">".uc($pipestyle)." PIPE ONLY</font></i><br>";
    print "<table style='font:12px verdana; border:1px solid black;' width=600>";
    print "<tr style='color:#FF0000'><td align=center><b>".uc($pipestyle)."</b></td><td align=center><b>".uc($pipestyle)."</b></td><td colspan=12 align=center><b>SDR</b></td></tr>\n";
    print "<tr style='color:#FF0000'><td align=center><b>Nominal</b></td><td><b>Actual</b></td>";
    foreach (@sdr){
    	print "<td><b>";
    	print sprintf "%.1f", $_;
    	print "</b></td>";
    }
    print "</tr>";
    $actual=@actual;
    for ($x=0; $x<$actual; $x++){
    	print "<tr><td><font color=red>".(sprintf "%.3f", @nominal[$x])."</font></td><td><font color=red>".(sprintf "%.3f", @actual[$x])."</font></td>";
    	for ($y=0; $y<12; $y++){
    		$val=(0.785*((POSIX::pow(@actual[$x],2))-(POSIX::pow(@actual[$x]-2*(@actual[$x]/@sdr[$y]),2)))*$pressure)/$ceca;
    		#$val = 0.785*((POSIX::pow(@actual[$x],2)));
    		#$val = POSIX::pow(@actual[$x]-2*(@actual[$x]/@sdr[$y])),2)
    		$val = int($val+.5);
    		print "<td>$val</td>";
    	}
    	print "</tr>";
    }
    print "</table><Br><br>".$mnote;
    print "<center><table style='font:12px verdana'><tr><td>Interfacial Pressure:</td><td><b>$pressure</b></td></tr>";
    print "<tr><td>Combined Effective Cylinder Area:</td><td><b>$ceca</b></td></tr>";
    print "</table></center>";	
    print "<br><br><i>You must also add drag pressure.  This is the hydraulic pressure required to move the carriage while holding the pipe, and is easily overlooked.  If two long pieces of pipe are being fused, the drag factor can reach several hundred pounds.";
    print "<br><br>This data is provided as a guide only and is believed to be accurate and reliable.  However, the user should always use the recommendations and procedures of the pipe manufacturer and/or the owner of the pipeline.  Due to the variability of applications and service conditions, no warranty, expressed or implied, is given in conjunction with the use of this data.</i>";
     
    }
    open (FILE,"<footer.txt");
    foreach (<FILE>){ print $_; }
    close (FILE);
     
    sub GetFormInput {
            (*fval) = @_ if @_ ;
            local ($buf);
            if ($ENV{'REQUEST_METHOD'} eq 'POST') {
                    read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
            }
            else {
                    $buf=$ENV{'QUERY_STRING'};
            }
            if ($buf eq "") {
                            return 0 ;
                    }
            else {
                     @fval=split(/&/,$buf);
                    foreach $i (0 .. $#fval){
                            ($name,$val)=split (/=/,$fval[$i],2);
                            $val=~tr/+/ /;
                            $val=~ s/%(..)/pack("c",hex($1))/ge;
                            $name=~tr/+/ /;
                            $name=~ s/%(..)/pack("c",hex($1))/ge;
     
     
                            if (!defined($field{$name})) {
                                    $field{$name}=$val;
                            }
                            else {
                                    $field{$name} .= ",$val";
     
                            }
     
     
                       }
                    }
    return 1;
    }

  2. #2
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check that the first line, the path to perl is correct, and make sure the perl file has been uploaded in ASCII mode and not binary mode (check your FTP clients help files) and that the cgi scripts permissions are correct, probably 755. Besides that there are no obvious problems to point out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •