Cannot modify header information

<form action="postabih.php" method="post">
Naziv vaše tvrtke:
<input type="text" name="name" size="25" /><BR><BR>
Vaša elektronska adresa:
<input type="text" name="email" size="25" value="@" /><BR>
<BR>
Poruka:<BR><BR>
<textarea rows="10" cols="45" name="comments"></textarea>
<input type="submit" value="Pošlji sporočilo" /></form>

tole je form za obrazec na strani.

Tole je koda .php skripte kjer javlja napako:

header( "Location: $thankyouurl" );

Tole je pa napaka:

Warning: Cannot modify header information - headers already sent by (output started at /web/d1/users/miliczo/www.keramika.si/bih/postabih.php:1) in /web/d1/users/miliczo/www.keramika.si/bih/postabih.php on line 81

A morda kdo ve kaj je narobe :S

hvala že vnaprej

5 odgovorov

Ja, ti bi rad v glavo dodal "Location: $thankyouurl", ampak nemoreš, ker je bila že poslana ....

pa verjetno boš moral pokazati malo več kode.

Poskusi čist na začetek dodati

ob_start();

Čisto na konec pa

obendflush();

Evo, tu je vsa koda zdaj :$

Mi dela recimo ista stvar v drugem direktoriju na isti strani :S

<?php
// ------------- CONFIGURABLE SECTION ------------------------

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto       = "youremailaddress@example.com" ;

$mailto = 'admin@planinec.si' ;

// $subject - set to the Subject line of the email, eg
//$subject  = "Feedback Form" ;

$subject = "Planinec kontakt" ;

// the pages to be displayed, eg
//$formurl      = "http://www.example.com/feedback.html" ;
//$errorurl     = "http://www.example.com/error.html" ;
//$thankyouurl  = "http://www.example.com/thankyou.html" ;

$formurl = "http://www.planinec.si/kontakt.html" ;
$errorurl = "http://www.planinec.si/neuspeh.html" ;
$thankyouurl = "http://www.planinec.si/uspeh.html" ;

$email_is_required = 1;
$name_is_required = 1;
$uself = 0;
$use_envsender = 0;
$use_utf8 = 1;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
if (!isset( $use_envsender )) { $use_envsender = 0 ; }
$envsender = "-f$mailto" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
    header( "Location: $formurl" );
    exit ;
}
if (($email_is_required && (empty($email) || !ereg("@", $email))) || ($name_is_required && empty($name))) {
    header( "Location: $errorurl" );
    exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
    header( "Location: $errorurl" );
    exit ;
}
if (empty($email)) {
    $email = $mailto ;
}

if (get_magic_quotes_gpc()) {
    $comments = stripslashes( $comments );
}

$messageproper =
    "Sporočilo je bilo poslano iz:\n" .
    "$http_referrer\n" .
    "------------------------------------------------------------\n" .
    "Ime pošiljatelja: $name\n" .
    "Email pošiljatelja: $email\n" .
    "------------------------- Sporočilo -------------------------\n\n" .
    $comments .
    "\n\n------------------------------------------------------------\n" ;

$headers =
    "From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.12.0" .
    $headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;

if ($use_envsender) {
    mail($mailto, $subject, $messageproper, $headers, $envsender );
}
else {
    mail($mailto, $subject, $messageproper, $headers );
}
header( "Location: $thankyouurl" );
exit ;

?>

hvala!

Kljucni del error sporocila je: output started at /web/d1/users/miliczo/www.keramika.si/bih/postabih.php:1, kar pomeni, da si v prvi vrstici datoteke postabih.php ze pisal v body in headerja pac ni mogoce vec posiljati. Poglej, kaj imas v prvi vrstici takega, kar bi lahko outputalo karkoli. Mozno je, da te zafrkavajo line-endings, ce z Windows masine FTPjas v binary modu na *nix masino, pa ti output naredi tisti CR, ki ga v *nix line-endingu ne bi smelo biti. V tem primeru uporabi ASCII mode v FTPju...

Odpri datoteko s hex editorjem in pobriši na začetku ali koncu dokumenta PRAZEN PROSTOR ali pa neke čudne znake.