警告:session_start():无法发送会话缓存限制器-标头已发送


Warning: session_start(): Cannot send session cache limiter - headers already sent

我有一个html表单,它发布到post_form.php进行处理。当我试图提交联系表格时,我收到了这个错误:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:'wamp'www'advanced-dynamic-php-form'form-files'post_form.php:1) in C:'wamp'www'advanced-dynamic-php-form'form-files'post_form.php on line 2
Call Stack
#   Time    Memory  Function    Location
1   0.0011  283424  {main}( )   ..'post_form.php:0
2   0.0011  284240  session_start ( )   ..'post_form.php:2

我已经检查了session_start();出现在打开php标记后的页面上。我还检查了php.ini文件,以确保session.auto_start=0。这是php页面:

<?php
session_start();
isset($_FILES['contact_form']);
$body = "";
if(isset($_POST["submit"])){
    if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"])
    {
        $to = "info@lexomatic.com";
        $subject = "Contact";
        $name = $_POST['name'];
        $email = $_POST['email'];
        $phone = $_POST['phone'];
        $address = $_POST['address'];
        $message = $_POST['message'];
        $total_lines = $_POST['total_lines'];

            $dirname = str_replace ("@","",$email);
            $allowed =  array('jpg', 'png', 'gif', 'doc', 'docx', 'pdf', 'xls', 'xlsx', 'zip', 'rar', 'JPG', 'PNG', 'GIF', 'DOC', 'DOCX', 'PDF', 'XLS', 'XLSX', 'ZIP', 'RAR');
            $i=0;
            $num_of_att = 0;
            $error_ext = 0;
            $error_size = 0;
            $upload_error =0;
            $target1 = "";
            $target2 = "";
            $target3 = "";
            $img_url1 = "";
            $img_url2 = "";
            $img_url3 = "";
            // File Attachment Function
            for ($file_num=1; $file_num<=3; $file_num++){
                ${'ok'.$file_num} = 0;
                $input_name = "file".$file_num;
                if(!empty($_FILES[$input_name]["name"] )){
                    ${'target'.$file_num} = $_SERVER['DOCUMENT_ROOT'] . '/form-files/uploads/'.$dirname .'/'. $_FILES[$input_name]["name"];
                    ${'img_url'.$file_num} = 'http://YOURSITEURL.COM/form-files/uploads/'.$dirname .'/'. $_FILES[$input_name]["name"];
                    $file_ext = $_FILES[$input_name]["name"];
                    $ext = end(explode(".", $file_ext));
                    //$file_ext = new SplFileInfo(${'target'.$file_num});
                    //$ext  = $file_ext->getExtension();

                    if(!in_array($ext,$allowed) ) {
                        $error_ext++;
                        $error_message = "<div style='width: 250px; color: red; font-family: Arial; font-weight: normal; font-size:12px'>Extensions " .$ext. " are not allowed</div>";
                    } elseif(($_FILES[$input_name]['size'] > 2097152) || ($_FILES[$input_name]['size'] == 0)){
                        $error_size++;
                        $error_message = "<div style='margin-left:15px; width: 250px; color: red; font-family: Arial; font-weight: normal; font-size:12px'>File " .$input_name. " exceeds max file size</div>";
                    }else{
                        ${'ok'.$file_num} = 1;
                        $num_of_att++;
                        ${'cur_temp_name'.$file_num} = $_FILES[$input_name]["tmp_name"];                        
                    } //close if
                }//close if
            }//close for
            // File attachment check
            $counter = 0;
            if(($num_of_att>0) && ($error_size==0) && ($error_ext==0)){ 
                if (!file_exists("uploads/".$dirname)) {
                    mkdir("uploads/$dirname", 0777, true);
                }
                if($ok1 == 1){
                    if(move_uploaded_file($cur_temp_name1, $target1)){
                        $counter++;
                    }else{
                        $upload_error++;
                    }
                }
                if($ok2 == 1){
                    if(move_uploaded_file($cur_temp_name2, $target2)){
                        $counter++;
                    }else{
                        $upload_error++;
                    }
                }
                if($ok3 == 1){
                    if(move_uploaded_file($cur_temp_name3, $target3)){
                        $counter++;
                    }else{
                        $upload_error++;
                    }
                }
            }   
                //////////////////////// Create Email Body ////////////////////////////////

        //  if(($num_of_att==0) && ($error_size==0) && ($error_ext==0)){
                    /*while (list($key,$value) = each($_POST)){
                        $body .= $key.": " .$value."'n";
                    }*/
            if(($upload_error == 0) && ($error_size==0) && ($error_ext==0)){    
                $body .= "Name: ".$name."'n";
                $body .= "Email: ".$email."'n";
                $body .= "Phone: ".$phone   ."'n";
                $body .= "Address: ".$address."'n";
                $body .= "Message: ".$message."'n'n";

                for($i=1; $i<=20; $i++){
                    $dynamicentryvaluefirst = 'dynamicentryvaluefirst'.$i;
                    $dynamicentryvaluesecond = 'dynamicentryvaluesecond'.$i;
                    $dynamicentryvaluethird = 'dynamicentryvaluethird'.$i;
                    $dynamicentryvaluefourth = 'dynamicentryvaluefourth'.$i;
                    $dynamicentryvaluefifth = 'dynamicentryvaluefifth'.$i;
                    if (isset($_POST[$dynamicentryvaluefirst])){
                        $cur_dynamicentryvaluefirst = $_POST[$dynamicentryvaluefirst];
                    }else{
                        $cur_dynamicentryvaluefirst ="";
                    }
                    if (isset($_POST[$dynamicentryvaluesecond])){
                        $cur_dynamicentryvaluesecond = $_POST[$dynamicentryvaluesecond];
                    }else{
                        $cur_dynamicentryvaluesecond ="";
                    }
                    if (isset($_POST[$dynamicentryvaluethird])){
                        $cur_dynamicentryvaluethird = $_POST[$dynamicentryvaluethird];
                    }else{
                        $cur_dynamicentryvaluethird ="";
                    }
                    if (isset($_POST[$dynamicentryvaluefourth])){
                        $cur_dynamicentryvaluefourth = $_POST[$dynamicentryvaluefourth];
                    }else{
                        $cur_dynamicentryvaluefourth ="";
                    }
                    if (isset($_POST[$dynamicentryvaluefifth])){
                        $cur_dynamicentryvaluefifth = $_POST[$dynamicentryvaluefifth];
                    }else{
                        $cur_dynamicentryvaluefifth ="";
                    }

                    ${'line'.$i} = $cur_dynamicentryvaluefirst . " | " . $cur_dynamicentryvaluesecond . " | " . $cur_dynamicentryvaluethird . " | " . $cur_dynamicentryvaluefourth . " | " . $cur_dynamicentryvaluefifth;
                    if(${'line'.$i} == (" |  |  |  | ")){
                    }else{
                        $body .= "Line".$i.": ".(${'line'.$i})."'n";
                    }
                }
                $body .= "'n"."File 1: ".$img_url1."'n";
                $body .= "File 2: ".$img_url2."'n";
                $body .= "File 3: ".$img_url3."'n";
                $sent = mail($to, $subject, $body); 
                //echo "Body----------------------"."<br/>".$body;
                echo "<div style='position: relative; top: -10px; margin-left:15px; width: 250px; color: green; font-family: Arial; font-weight: normal; font-size:12px'><img src='tick-icon.png' width='70px' /><div id='message_result'>The form submitted successfully.</div></div>";
            }else{
                echo "<div style='margin-left:15px; width: 250px; color: red; font-family: Arial; font-weight: normal; font-size:12px'><img src='delete-icon.png' width='70px' /><div id='message_result'>An error occured while uploading the file(s).<br/>". $error_message . "</div></div>";
            }   
        }else{
            echo "<div style='margin-left:15px; width: 250px; color: red; font-family: Arial; font-weight: normal; font-size:12px'><img src='delete-icon.png' width='70px' /><div id='message_result'>Wrong security code number.</div></div>"; // invalid code
        }   
}else{
    echo "<div style='margin-left:15px; width: 250px; color: red; font-family: Arial; font-weight: normal; font-size:12px'><img src='delete-icon.png' width='70px' /><div id='message_result'>An error occured. <br/>Please check file sizes and types & try again.</div></div>";
    session_destroy();
}

?>

如有任何协助,我们将不胜感激。

假设<?php ...... ?>之间的所有内容都将被删除,那么剩下的内容将以html的形式"输出"到浏览器。

这总是一个p-i--a,因为php标记前后的换行符、空格、退格等不可见字符,甚至它们之间的字符都可能会打乱输出。

像这样的东西

<?php
      /**
       * some comments
       */
?>
<?php
...

你需要几个小时才能找到。这里:?>和第二个<?php 之间的两个(!)nl