2012-07-20 64 views
-5

可能重複標題:
Headers already sent by PHP無法修改標題信息 - 在OOP PHP已經發出已

我在面向對象的PHP新。我有一些我無法解決的問題。我的問題是,當我想登錄/註銷,然後一些錯誤消息出來瞭如下圖所示:: [注意它運作良好,在功能的PHP,但問題是在接力PHP]

錯誤::

Warning: Cannot modify header information - headers already sent by (output 
started at E:\XAMPP\xampp\htdocs\photo_gallery_new\Includes\database_object.php:6) 
in E:\XAMPP\xampp\htdocs\photo_gallery_new\Includes\Functions.php on line 14 

我的代碼::

的index.php

<?php require_once ("../../Includes/initiate.php"); ?> 
<?php 
if(!$session->is_logged_in()) { 
    redirect_to("login.php"); 
} 
?> 

的login.php

<?php 
require_once ("../../Includes/initiate.php"); 

if($session->is_logged_in()) { 
    redirect_to("index.php"); 
} 
// Remember to give your form's submit tag a name="submit" attribute! 
if(isset($_POST['submit'])) { // form has been submitted 
    $username = trim($_POST['username']); $password = trim($_POST['password']);  
    // Check database to see if username/password exist  
    $found_user = USER::authenticate($username, $password);  
    if($found_user) { 
     $session->login($found_user); 
     redirect_to("index.php"); 
    } else { 
     // username/password combo was not found in the database 
     $message = "Username/password combination incorrect."; 
    } 
} 
else { // form has not been submitted 
    $username = ""; 
    $password = ""; 
} 
?> 

<html> 
    <---- form design [ form action = 'login.php' ] ---> 
</html> 

initiate.php

<?php 
     require_once ("session.php"); 
     require_once ("Config.php"); 
     require_once ("Functions.php"); 
     require_once ("Database.php"); 
    require_once ("database_object.php"); // this makes error 
    require_once ("user.php"); 
    ?> 

function.php

<?php  
function strip_zeros_from_date($marked_string="") { ..... } 

function redirect_to($location = NULL) { // check loged in/not 
    if($location != NULL) { 
     header("Location: {$location}"); 
     exit; 
    } 
} 

function output_message($message = "") { .... } 

function __autoload($class_name) { ...... } 

function include_layout_template($template = "") { ... } 
?> 

initiate.php

<?php 
require_once ("database.php"); 
class databaseObject {  
} 
$newClass = new databaseObject(); 
?> 
+3

請參閱本頁右側的相關問題。 – 2012-07-20 20:15:20

+0

^那。此外,在問題似乎是兩頁的頁面中,您沒有提供一個,並且給我們提供了關於另一個的基本無價值的信息。 – Palladium 2012-07-20 20:17:20

+0

是的,您應該檢查database_object.php以及所有其他頁面,並且在使用header()函數之前不要輸出任何文本,消息,甚至沒有空白空間。 – Stano 2012-07-20 20:20:24

回答

1

header信息必須第一件事修改。換句話說,在任何事情回到客戶端之前。

相關問題