2016-11-11 116 views
0
發送的標題

我閱讀了有關此標題的主題,但無法使其適用於我的程序。我之前刪除了html和空格,但仍然看不到有什麼問題。 connect.php文件的目的是連接到數據庫,我使用app_config.php文件從connect.php調用handle_error函數來打印嘗試連接到數據庫時發生的任何錯誤。非常感謝您的幫助!無法修改標題信息 - 已由

錯誤是:

警告:不能更改頭信息 - 頭已經發出在/ home3(輸出開始/home3/alfredbiz/public_html/phpMM/ch05/scripts/connect.php:1) /alfredbiz/public_html/phpMM/ch05/app_config.php第12行

這裏是connect.php

<?php 
//appel le fichier de mot de passe 
require_once '/home3/alfredbiz/public_html/phpMM/ch05/app_config.php'; 
require_once '/home3/alfredbiz/public_html/phpMM/ch05/app_connexion.php'; 

//database connexion 
$link = mysqli_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME); 

// check connection 
if (!$link) { 
$user_error_message = "there was a problem connecting to the database that holds the information we need to get you connected."; 
$system_error_message = mysqli_connect_error(); 
handle_error($user_error_message, $system_error_message); 
} 

//editer les tables avec controle d erreur 
$result = mysqli_query($link, "show tables"); 
if(!$result){ 
    die("<p>Error in Listing tables: " .mysql_error() . "</p>"); 
} 
echo "<p> requette executee avec success</p>"; 
?> 

app_config.php

<?php 
//set up debug mode 
define("DEBUG_MODE", true); 

function debug_print($message) { 
if(DEBUG_MODE) { 
echo $message; 
    } 
} 

function handle_error($user_error_message, $system_error_message) { 
header("location: /home3/alfredbiz/public_html/phpMM/ch05/scripts/show_error.php?" ."error_message={$user_error_message}&" ."system_error_message= {$system_error_message}"); 
exit(); 
} 
?> 
+0

看看你的輸出。該錯誤消息之前可能有一行。 – aynber

+0

發佈配置以及。'ob_start();'通常情況下訣竅 –

回答

0

這是BOM(字節順序標記)造成的常見錯誤。此指標是輸出開始於第1行的事實。

請參閱複製線程How to fix "Headers already sent" error以獲得解決方案。

+0

只要我用notepad ++將其轉換爲UTF-8我有這個錯誤警告:無法修改頭信息 - 頭已經發送(輸出開始於/ home3/alfredbiz /public_html/phpMM/ch05/scripts/connect.php:7)在/home3/alfredbiz/public_html/phpMM/ch05/app_config.php上線12 – Alfred

+0

仍然我看不到任何空格或html在第7行 – Alfred

+0

請閱讀字節順序標記。 – ChristianF

0

這很可能是app_config.php文件中導致問題的回聲。一旦你迴應任何東西,你不能改變標題信息。你會想要在handle_error函數中的header()之後移動回顯。

+0

我刪除了app_config中的回聲,但沒有更改 – Alfred

相關問題