可能重复:
PHP 已发送的标头
我是面向对象的 php 新手。我有一些我无法解决的问题。我的问题是,当我想登录/注销时,会出现一些错误消息,如下所示:: [注意它在功能性 php 中运行良好,但问题出在 oop 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
我的代码::
索引.php
<?php require_once ("../../Includes/initiate.php"); ?>
<?php
if( !$session->is_logged_in() ) {
redirect_to("login.php");
}
?>
登录.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>
启动.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");
?>
函数.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 = "" ) { ... }
?>
启动.php
<?php
require_once ("database.php");
class databaseObject {
}
$newClass = new databaseObject();
?>