会话启动,无法修改标头


Session start and cannot modify header

我在错误日志上有这个问题:

PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/site/public_html/index.php:1) in /home/site/public_html/controller/controller.php on line 5   <---   and this on admin panel error log --->  PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/site/public_html/config.php:1) in /home/site/public_html/functions/functions.php on line 24
PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/site/public_html/config.php:1) in /home/site/public_html/admin/auth/index.php on line 8

在我的本地服务器上一切正常,但在托管时我无法正常使用管理面板。 我必须在浏览器上键入完整路径以进行连接,并且我在管理上更改了一些内容,我必须再次路径。 对不起,我的英语不好,如果有人1理解我,请帮助。

<?php
define('site', TRUE);
session_start();
include $_SERVER['DOCUMENT_ROOT'].'/config.php';
if($_SESSION['auth']['admin']){
header("Location: ../");
exit;
}
if($_POST){
$login = trim(mysql_real_escape_string($_POST['user']));
$pass = trim($_POST['pass']);
$query = "SELECT .......................... = '$login' AND id_role = 2 LIMIT 1";
$res = mysql_query($query);
$row = mysql_fetch_assoc($res);
if($row['password'] == md5($pass)){
$_SESSION['auth']['admin'] = htmlspecialchars($row['name']);
$_SESSION['auth']['user_id'] = $row['customer_id'];
header("Location: ../");
exit;
}else{
$_SESSION['res'] = '<div class="error">wrong pass!</div>';
header("Location: {$_SERVER['PHP_SELF']}");
exit;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"                                                   ....    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../<?=ADMIN_TEMPLATE?>style.css" />
<title>admin</title>
</head>
<body>
<div class="karkas">
<div class="head">
    <a href="#"><img src="../<?=ADMIN_TEMPLATE?>images/logoAdm.jpg" /></a>
    <p>log admin</p>
</div>
<div class="enter">
<?php 
if(isset($_SESSION['res'])){
echo $_SESSION['res'];
unset($_SESSION['res']);
}
?>
<form method="post" action="">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Username:</td>
<td><input type="text" name="user" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pass" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="image" src="../<?=ADMIN_TEMPLATE?>images/enter_btn.jpg" name="submit" /></td>
</tr>
</table>      
</form>
</div>
</div>
</body>
</html>

配置。.PHP

<?php
defined('site') or die('Access denied');
define('PATH', 'http://site');
define('MODEL', 'model/model.php');
define('CONTROLLER', 'controller/controller.php');
define('VIEW', 'views/');
define('TEMPLATE', PATH.VIEW.'site/');
define('PRODUCTIMG', PATH.'userfiles/product_img/baseimg/');
define('GALLERYIMG', PATH.'userfiles/product_img/');
define('SIZE', 1048576);
define('HOST', 'localhost');
define('USER', 'sdfsdfsdfsd');
define('PASS', 'sdfsdfsdfsd');
define('DB', 'sdfsdfsdfsd');
define('TITLE', 'სახლი რომელიც შენია!');
define('ADMIN_EMAIL', 'admin@site.com');
define('PERPAGE', 9);
define('ADMIN_TEMPLATE', 'templates/');
mysql_connect(HOST, USER, PASS) or die('No connect to Server');
mysql_select_db(DB) or die('No connect to DB');
mysql_query("SET NAMES 'UTF8'") or die('Cant set charset');

身份验证索引文件

<?php
define('site', TRUE);
session_start();
include $_SERVER['DOCUMENT_ROOT'].'/config.php';
if(!$_SESSION['auth']['admin']){
header("Location: " .PATH. "admin/auth/enter.php");
exit;
}else{
header("Location: " .PATH. "admin/");
exit;
}

一开始就尝试ob_start();

这将缓冲输出,直到脚本结束,并且在大多数情况下,您不会收到"无法修改标头信息"警告。更多信息在这里。你的代码应该是这样的(你HTTP请求的第一个文件):

<?php
ob_start();
session_start();
define('site', TRUE);
include $_SERVER['DOCUMENT_ROOT'].'/config.php';
...

特别是在您的代码中,警告似乎是由您的(headerdie)尝试创建的,因此应该在之前启用缓冲。

此外,由于警告位于第一行,这意味着输出应该发生在那里,并且前提是您那里没有任何额外的空格和缩进,请检查文件的编码(索引.php,config.php)并将它们保存为没有BOM的UTF-8