#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Washington, DC
    Posts
    12
    Rep Power
    0
    Hey Guys, I have a problem with a perl script. When I rem out my sub proccesses it renders the output html page fine, when I run my two subproccesses it gives me the following error message:malformed header from
    script. Bad header=EOT: /home/cust1/usr1216/cgi-bin/order.pl

    now the sub routines call the mailto function, and each routine sends its email message fine. I think the problem may be how long these sub routines take to fire. Is there anyway I can get my perl script to call these subs and then not wait for them to complete while writing the rest of the web page? Does anyone have an Idea on this?
  2. #2
  3. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>malformed header from script. Bad header

    You need this line -> print "Content-type: text/htmlnn";

    >>I think the problem may be how long these sub routines take to fire.

    No.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Washington, DC
    Posts
    12
    Rep Power
    0
    Nah I already have that bit with
    the print "Content-type: text/htmlnn";

    This does bring up the interesting question though, how many new lines can occur
    after that without any html or text being
    presented.

    To clarify here's sort of whats going on in the perl script:
    an If statement that decides which html document to print.
    first line after the if and after the else (and no they can never both fire) is the
    print "Content-type: text/htmlnn";
    line. The problem is that in the if statement after I call that If I call my two subs that send mail and then try to print out the web page I get the malformed header problem. If I rem out these two subs the page prints fine. I looked very hard at the mailto subs and the only thing I could think of is that they are sending some sort of "close header" response upon sending a message. I don't really know. Any help here would be greatly apreciated!!!

    -nate
  6. #4
  7. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    I always just creat a header sub routine and call it before html output.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Washington, DC
    Posts
    12
    Rep Power
    0
    That sounds like a good idea, would you
    mind posting your subroutine? I'm still getting the hang of this perl thing. =)
    (do you fork the proccess or what?)
  10. #6
  11. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>The problem is that in the if statement after I call that If I call my two subs

    Try not to do this:

    if (blah blah) {
    many lines here
    }
    else {
    many other lines here
    }

    In some situations, you can also put this line about the if else block ->
    print "Content-type: text/htmlnn";

    >>send mail and then try to print out the web page I get the malformed header problem.

    You probably left out print "Content-type: text/htmlnn"; somewhere.

    If your script is less than 100 lines long, please post it here so we can do some cleanup and bugfix for you.
  12. #7
  13. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    Yes, please post the code... I'd be interested in seeing it.

    As for the sub routine, here ya go:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    sub header {
    print "Content-type: text/htmlnn";
    }
    [/code]
    Then to call it just type:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    &header;
    [/code]

    You can put the sub routine at the bottom of your perl script (in fact that what the standard is). It doesn't have to come before you call it.
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Washington, DC
    Posts
    12
    Rep Power
    0
    okay here is about 100 lines of the script. This bit doesn't include the sub routines, I can include those in a followup message if there is interest... -nate

    if ($cname && $card && $cnum && $cexm && $cexy)
    {

    print "Set-Cookie: ShopCart=$cart; path=/; expires=Monday, 7-Apr-01 20:00:00 GMT; secure;n";
    print "Content-type: text/html nn";

    #Read In User Information From ID File
    open(ID,$userdir.$id) &#0124; &#0124; die "!ERROR: Open $id File FAILED";
    @idfile=<ID>;
    close(ID);

    @sinfo= split (/|/, $idfile[0]);

    $dd = `date`;
    $name=$sinfo[0];
    $address=$sinfo[1];
    $city=$sinfo[2];
    $state=$sinfo[3];
    $zip=$sinfo[4];
    $country=$sinfo[5];
    $email=$sinfo[6];
    $phone=$sinfo[7];

    #print "<BR>$name<BR>$userdir.$id<BR>$sinfo[0]<BR>";


    $intnum = int ($total);
    $pointadd = $intnum * 10;

    $sinfo[9] += $pointadd;
    open(ID, "> ".$userdir.$id) &#0124; &#0124; die "!Cookie,!Form: Error Opening ID File";
    print ID "$sinfo[0]|$sinfo[1]|$sinfo[2]|$sinfo[3]|$sinfo[4]|$sinfo[5]|$sinfo[6]|$sinfo[7]|$sinfo[8]|$sinfo[9]n";
    close (ID);
    chmod (0666, $userdir.$id);

    print <<SHANK;

    <HTML>
    <TITLE>Black Belt Order Confirmation</TITLE>
    <BODY background="/gifs/back.gif" link=#fa7700 vlink=#aa99ff>

    <table>
    <tr>
    <td width=160 valign=top>

    SHANK

    open(IN,"/home/cust1/usr1216/html/navigation.txt");
    @navigation=<IN>;
    close(IN);
    print @navigation;

    print <<SHANK;
    </td>

    <td width=530 valign=top>
    <CENTER>
    <font face=arial><B>
    Thank you for ordering from Black Belt.
    <br>
    You should recieve an email receipt shortly.
    </B></font>
    </CENTER>
    </td>
    </tr>
    </table>
    </BODY>
    </HTML>

    SHANK

    # This really shouldn't be down here, but do to weird parsing error with headers it is shoved down here, learn more perl and fix.
    $SIG{&do_mail} = sub { wait };
    $SIG{&do_receipt} = sub { wait };

    }
    else {

    calc_prices();

    print "Content-Type: text/htmlnn";

    print <<POON;

    <HTML><HEAD><TITLE>Black Belt Ordering Credit Card Information</TITLE></HEAD>
    <BODY background="/gifs/back.gif" link=#fa7700 vlink=#aa99ff>

    <table>
    <tr>
    <td width=160 valign=top>
    POON

    open(NAV,"/home/cust1/usr1216/html/navigation.txt");
    @navigation=<NAV>;
    close(NAV);
    print @navigation;

    print <<POON;
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Washington, DC
    Posts
    12
    Rep Power
    0
    errr I forgot to put the two subroutines back at the top where I had them. They originally followed the following two lines:

    print "Set-Cookie: ShopCart=$cart; path=/; expires=Monday, 7-Apr-01 20:00:00 GMT; secure;n";
    print "Content-type: text/html nn";
  18. #10
  19. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>$intnum = int ($total);
    >>$pointadd = $intnum * 10;

    $intum and $total have no references at all.

    >>open(ID, "> ".$userdir.$id) | | die "!Cookie,!Form: Error Opening ID File";

    What are you trying to do with it? It's an existing file and you want to write a new line?
    open(ID,">>$userdir.$id");

    #############################################
    open(IN,"/home/cust1/usr1216/html/navigation.txt");
    @navigation=<IN>;
    close(IN);
    #############################################
    I would put these within this two lines on top:
    print "Content-type: text/html nn";

    #Read In User Information From ID File


    If open(IN,"/home/cust1/usr1216/html/navigation.txt"); fails, you probably wanna send an error message and exit since this is independent.
    You can always -> print "@navigationn"; later down the bottom.

    chmod (0666, $userdir.$id);
    #Your sendmail subroutine should go here
    #it could look as simple as &do_mail;
    print <<SHANK;

    You really need to cleanup/separate your codes and try not to mix html and your perl together.


  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Washington, DC
    Posts
    12
    Rep Power
    0
    thanks for all the help guys! I think
    i've got it working a bit more efficiently.
    I didn't originally write the code (dodge responsibility for bad code) I'm actually just porting it over from one system to another and trying to modernize it a little. (though I don't really know perl all that well yet) Anyhow, all of your posts helped me a lot. =)

IMN logo majestic logo threadwatch logo seochat tools logo