发送后形成问题(cookie问题)

时间:2010-02-28 10:37:22

标签: php forms

提交表单后我收到一个奇怪的错误,错误就是这个:

        Warning: Cannot modify header information - headers already sent by 
        (output started at
        /var/www/g35003/coldcharlie.nl/subdomains/test/mailer.php:6) in 
        /var/www/g35003
        /coldcharlie.nl/subdomains/test/mailer.php on line 96

第96行包含此

// delete the cookie so it cannot sent again by refreshing this page
    setcookie('tntcon','');

这是完整的mailer.php

// ----------------------------------------- 
//  The Web Help .com
// ----------------------------------------- 
// remember to replace you@email.com with your own email address lower in this code.

// load the variables form address bar
$subject = $_POST["subject"];
$message = $_POST["message"];
$from = $_POST["from"];
$verif_box = $_POST["verif_box"];

// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message); 
$subject = stripslashes($subject); 
$from = stripslashes($from); 

// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
    // if verification code was correct send the message and show this page
    mail("info@friesecomputerservice.nl", 'Online Formulier: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message, "From: $from");
    // delete the cookie so it cannot sent again by refreshing this page
    setcookie('tntcon','');
} else if(isset($message) and $message!=""){
    // if verification code was incorrect then return to contact page and show error
    header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
    exit;
} else {
    echo "no variables received, this page cannot be accessed directly";
    exit;
    }
?>

这是我mailer.php的主要部分

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="Computerhulp voor Particulieren en MKB in Leeuwarden en de rest van Friesland" />
    <meta name="keywords" content="computerhulp in friesland, pc service, Leeuwarden, Sneek, Drachten, Heerenveen, Bolsward, Buitenpost, Franeker, Gorredijk, Dokkum, Joure, Oosterwolde, Koudum, Harlingen " />
    <title>Computer stuk? Computerhulp nodig? Friese Computer Service - Leeuwarden, Sneek, Drachten, Heerenveen, Bolsward, Buitenpost, Franeker, Gorredijk, Dokkum, Joure, Oosterwolde, Koudum, Harlingen, Computerhulp Friesland</title>
    <link rel="bookmark" href="/favicon.ico" />
    <link rel="shortcut icon" href="/favicon.ico" />

    <link href="http://www.coldcharlie.nl/test/css/style.css" rel="stylesheet" type="text/css" />
  </head>

1 个答案:

答案 0 :(得分:1)

只有在尚未发送到客户端的情况下才能修改HTTP标头。当你打印出来的时候就会发生这种情况。

在您的情况下,输出从 mailer.php 文件中的第6行开始。您可以使用output buffer functions并缓冲输出以避免这种情况。