可能重複:
Headers already sent by PHP在session_start()[function.session啓動]:不能發送會話cookie - 標題已經發出已
我在面向對象的PHP新。此代碼在函數php中運行良好,但它在OOP PHP中造成一些錯誤。
當我打開的index.php然後錯誤消息等作爲表演之下,但所有其他的代碼工作很好::
Warning: session_start() [function.session-start]: Cannot send session cookie - headers
already sent by (output started at
E:\XAMPP\xampp\htdocs\photo_gallery_new\public\layout\header.php:14) in
E:\XAMPP\xampp\htdocs\photo_gallery_new\Includes\session.php on line 15
Warning: session_start() [function.session-start]: Cannot send session cache limiter -
headers already sent (output started at
E:\XAMPP\xampp\htdocs\photo_gallery_new\public\layout\header.php:14) in
E:\XAMPP\xampp\htdocs\photo_gallery_new\Includes\session.php on line 15
代碼::
的index.php
<?php include ("../public/layout/header.php"); ?> // for design header
<h2> Menu </h2>
<?php
require_once ("../Includes/initiate.php"); // it makes error
//require_once ("../Includes/user.php"); // it works
//require_once ("../Includes/database_object.php"); // it makes error
echo $user->full_name();
echo "<hr />";
?>
</div>
<?php include ("../public/layout/footer.php"); ?> // design for footer
user.php
<?php
require_once ("database.php");
class USER extends databaseObject { // it makes error
//class USER { // but it works
public $id; public $username; public $password; public $firstName;
public $lastName;
// user authenticate
public static function authenticate($username="", $password="") { ... }
public function full_name() {..... } // find full name
// common database action
public static function record_all_user() { ... } // find all user
public static function record_by_id($id=0) {.....} // find specific user
public static function record_by_sql($sql="") { ...... } // check sql
?>
的header.php
<html>
<head>
<title> Photo Gallery </title>
<link href="stylesheet/main.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<h1> PHOTO GALLERY </h1>
</div>
<div id="main">
session.php文件
<?php
class Session {
private $logged_in = FALSE;
public $user_id;
function __construct() {
session_start();
$this->check_login();
.............................
}
public function is_logged_in() {....} // check loged in
public function login($user) { ..... }
public function logout() {
unset($_SESSION['user_id']);
unset($this->user_id);
$this->logged_in = FALSE;
}
private function check_login() {... .} // check login
}
$session = new Session();
?>
initiate.php
<?php
require_once ("Config.php");
require_once ("Functions.php");
require_once ("session.php");
require_once ("Database.php");
require_once ("database_object.php"); // this makes error
require_once ("user.php");
?>
database_object.php
<?php
require_once ("database.php");
class databaseObject {
}
$newClass = new databaseObject();
?>
由於index.php中包含的順序,輸出仍將在創建會話之前創建。在'header.php'之後調用'initiate.php',它會產生輸出。 – Andy0708 2012-07-20 14:09:54
你是對的。還沒有看到它。抱歉。 – ralphkurz 2012-07-20 14:13:21