无法修改标题信息 - 在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();
?>
答
header
信息必须第一件事修改。换句话说,在任何事情回到客户端之前。
请参阅本页右侧的相关问题。 – 2012-07-20 20:15:20
^那。此外,在问题似乎是两页的页面中,您没有提供一个,并且给我们提供了关于另一个的基本无价值的信息。 – Palladium 2012-07-20 20:17:20
是的,您应该检查database_object.php以及所有其他页面,并且在使用header()函数之前不要输出任何文本,消息,甚至没有空白空间。 – Stano 2012-07-20 20:20:24