Ask Experts Questions for FREE Help !
Ask
    ungureaa's Avatar
    ungureaa Posts: 6, Reputation: 1
    New Member
     
    #1

    Dec 15, 2005, 09:01 AM
    CGI for Apache - Premature end of script headers
    I have a post form on my Web site in Common Gateway Interface (CGI) but when people click in order to post it, the message Premature end of script headers: mailform.cgi appears. If you'd like to see what I'm talking about please go to this page : http://www.accesss.net/pnjoindre.html.

    How can I resolv this matter ? I have the codes so if you leave me the mail, I can post you the whole .cgi form.

    Thanks !
    psi42's Avatar
    psi42 Posts: 599, Reputation: 13
    Senior Member
     
    #2

    Dec 15, 2005, 11:04 AM
    Something is going wrong when your CGI script is executed. Check the apache logs and any other output the script is written to produce to see what is going on.
    Roel Zylstra's Avatar
    Roel Zylstra Posts: 84, Reputation: 14
    Tech entrepreneur, perpetual student,lover of life
     
    #3

    Dec 15, 2005, 11:06 AM
    Make sure that your script is returning something to the browser, starting with something equivalent to
    Code:
    print "Content-type: text/html\n\n";
    Or maybe you are trying to use sendmail with the wrong path or parameters?

    If those don't work, try seeing a more detailed error message by including
    Code:
    use CGI::Carp qw(fatalsToBrowser);
    in your script.
    ungureaa's Avatar
    ungureaa Posts: 6, Reputation: 1
    New Member
     
    #4

    Dec 15, 2005, 01:03 PM
    Me again
    Here is the bloody script - I HATE it ! What's wrong with it ? :mad:

    #!/usr/local/bin/perl
    # mailform.cgi
    # Copyright (C) 1997 William E. Weinman
    #
    # generic CGI email generator
    # change $malto, $subject, and $sendmail to use
    #
    # This program is free software; you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation; either version 2 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program; if not, write to the Free Software
    # Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA.
    #
    # where to send the mail
    $mailto = "adina.ungureanu@accesss.net";
    # a default subject line
    $subject = "Message du Formulaire";
    # your sendmail location. Ask your system administrator.
    # or just try this, it works most of the time
    $sendmail = "/usr/sbin/sendmail -t";

    # DON'T MODIFY BELOW THIS LINE
    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    $mailfrom = $mailto;
    $sendmaildashfokay = 1;
    $program = "mailform.cgi";
    $version = "1.0";
    $byline = "(by Bill Weinman <wew\@bearnet.com>)";
    print "content-type: text/html\n\n";
    %q = getquery();
    $emessage = "$subject:\n\n";
    foreach $k (sort keys %q) {
    $emessage .= "$k : $q{$k}\n"
    }
    $emessage .= "\n---\n Sent by $program $version $byline\n";
    sendmessage();
    done();
    sub done
    {
    print <<HERE;
    <title> $subject </title>
    <body bgcolor=white>
    <h1>$subject</h1>
    <p> Your message has been sent.
    <pre>
    $emessage
    </pre>
    HERE
    }
    # sendmessage
    #
    # sends email to $mailto from $mailfrom
    # with $subject and $emessage
    #
    sub sendmessage
    {
    $dashf = $sendmaildashfokay ? "-f $mailfrom" : "";
    open(SENDMAIL, "|$sendmail $dashf") or die "can't open $sendmail\n";
    print SENDMAIL "X-Mailer: $program $version $byline\n";
    print SENDMAIL "From: $mailfrom\n";
    print SENDMAIL "To: $mailto\n";
    print SENDMAIL "Subject: $subject\n";
    print SENDMAIL "\n";
    print SENDMAIL "$emessage\n";
    close SENDMAIL;
    }

    # getquery
    #
    # returns hash of CGI query strings
    #
    sub getquery
    {
    my $method = $ENV{'REQUEST_METHOD'};
    my $query_string, $pair;
    my %query_hash;
    my $sep = $/;
    undef $/;
    $query_string = $ENV{'QUERY_STRING'} if $method eq 'GET';
    $query_string = <STDIN> if $method eq 'POST';
    $/ = $sep;
    return undef unless $query_string;
    foreach $pair (split(/&/, $query_string)) {
    $pair =~ s/\+/ /g;
    $pair =~ s/%([\da-f]{2})/pack('c',hex($1))/ieg;
    ($_qsname, $_qsvalue) = split(/=/, $pair);
    $query_hash{$_qsname} = $_qsvalue;
    }
    return %query_hash;
    }
    psi42's Avatar
    psi42 Posts: 599, Reputation: 13
    Senior Member
     
    #5

    Dec 20, 2005, 12:59 PM
    The script looks fine to me. Have you checked the apache logs like I suggested?
    ungureaa's Avatar
    ungureaa Posts: 6, Reputation: 1
    New Member
     
    #6

    Dec 23, 2005, 04:45 PM
    No because I don't know how to check it... :(
    psi42's Avatar
    psi42 Posts: 599, Reputation: 13
    Senior Member
     
    #7

    Dec 25, 2005, 07:20 PM
    Quote Originally Posted by ungureaa
    No because I don't know how to check it...:(
    Do you have root/administrator privileges on the server?

    What operating system is the server running?
    Roel Zylstra's Avatar
    Roel Zylstra Posts: 84, Reputation: 14
    Tech entrepreneur, perpetual student,lover of life
     
    #8

    Dec 25, 2005, 10:41 PM
    Or did you try any of the things I suggested?
    ungureaa's Avatar
    ungureaa Posts: 6, Reputation: 1
    New Member
     
    #9

    Dec 26, 2005, 09:37 AM
    Yes I have administrator rights and the system runs with Apache. But because I'm new on that, I don't know what I can run a script nor how to look for http headers.
    Thanks !
    psi42's Avatar
    psi42 Posts: 599, Reputation: 13
    Senior Member
     
    #10

    Dec 26, 2005, 12:04 PM
    Quote Originally Posted by ungureaa
    Yes I have administrator rights and the system runs with Apache. But because I'm new on that, I don't know what I can run a script nor how to look for http headers.
    What operating system is the server running?
    Also, did you try what admin suggested?
    ungureaa's Avatar
    ungureaa Posts: 6, Reputation: 1
    New Member
     
    #11

    Dec 26, 2005, 12:21 PM
    I don't know about the server, it is a provider that can tell that. My rights are to modify any file that goes on my web site www.accesss.net
    I did what admin told me but it didn't work any better. I might also ask where should I put those phrases in my script?
    Thanks !
    psi42's Avatar
    psi42 Posts: 599, Reputation: 13
    Senior Member
     
    #12

    Dec 26, 2005, 12:31 PM
    Quote Originally Posted by ungureaa
    I don't know about the server, it is a provider that can tell that. My rights are to modify any file that goes on my web site www.accesss.net
    I did what admin told me but it didn't work any better. I might also ask where should I put those phrases in my script?
    Thanks !
    Okay, so you don't have administrator privileges on the server? Can you actually log into the machine that runs apache?
    ungureaa's Avatar
    ungureaa Posts: 6, Reputation: 1
    New Member
     
    #13

    Dec 26, 2005, 12:36 PM
    No I cannot, and even if I could, I don't know much about Apache
    psi42's Avatar
    psi42 Posts: 599, Reputation: 13
    Senior Member
     
    #14

    Dec 26, 2005, 02:10 PM
    Quote Originally Posted by ungureaa
    No I cannot, and even if I could
    Okay, so you have no access to the server's logs?

    Sigh... I suppose we'll have to do this the hard way. See, errors encountered by the perl interpreter should be logged to the apache logs, so we could see what is going on.

    Again, have you tried what admin suggested?

    Quote Originally Posted by ungureaa
    I don't know much about Apache
    I'd _really_ suggest you read up on it. CGI is pretty dangerous stuff, and you should make sure you know what you are doing before publishing a public CGI script. ;)

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Script error [ 1 Answers ]

I have downloaded file to my documents to solve a script error but cannot seem to install it to where it is required(internet explorer), can anybody help this confused idiot. Thank you :confused:

Grey Hair - Premature [ 3 Answers ]

What causes grey hair, besides the commonly known strees, inherited, lack of melanin in hair? Is lack of protein one of the cause? What is the remedies to cure grey hair. I have try vit B, it doesn't work for me any more. I found that dye hair will cause more grey hair for people like us who...

Help with script [ 2 Answers ]

Hey it's me again about my script. I'm writing out of my element about magic and witches and stuff like that. The way i'm writing it sounds very corny and fake. Maybe it's just that i am horrible at writing. Can anybody read it and tell me how to make it sound less fake and stupid? Also, I need a...

Apache User Authentication issue.please help [ 6 Answers ]

I'm trying to restrict access to a directory on my apache webserver. Before I go into detail I'll show what I've got so far. I've successfully created the Password file. Here's the code in httpd.conf DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs" ... ... <Directory />

Script writing [ 1 Answers ]

How do I translate foreign dialogue in a movie script?


View more questions Search