【发布时间】:2011-08-09 07:29:54
【问题描述】:
可能的重复:
Warning: Cannot modify header information - headers already sent by
what is output buffering?
我最近从 Bluehost 购买了一个托管计划,并将我的网站搬到了这里。之前,我的网站可以正常工作,我没有收到任何错误,但现在,当我尝试登录时,我收到了这个错误:
警告:无法修改标头信息 - 标头已由第 84 行 /home/rugbyspi/public_html/index.php 中的 /home/rugbyspi/public_html/inc/offline_header.php:15 发送的标头
问题在于标头函数。我想我不能在代码中间使用这个功能,但在我的另一台主机上我可以做到这一点。 知道如何解决这个问题吗?
<?php
session_start();
if (isset($_SESSION['username'])) {
include_once('inc/homepage_header.php');
include_once('lib/stats_func.php');
include_once('lib/user_time_func.php');
update_last_active($username);
?>
<div id="right_menu">
<?php include_once('inc/sidebar_statistics.php'); ?>
<br/>
<?php include_once('inc/sidebar_follow.php'); ?>
</div>
<div id="content">
<div class="text">
<br/>
<h2 class="hr"><?php echo $lang['ann']; ?></h2>
<?php
if(!isset($_REQUEST["start"])) {
$start = 0;
}
else {
$start = $_REQUEST["start"];
}
$query = mysql_query ("SELECT * from news where lang='$language'")
or die ("Couldn't connect to the do database.");
$d=0;
$f=0;
$g=1;
$query = mysql_query ("SELECT * from news where lang='$language' order by id DESC Limit $start, 7") or die ("Couldn't connect to the do database.");
while($news = mysql_fetch_array($query)) {
?>
<h3 class="hr"><font size=1><?php echo $news['tsubmit']; ?></font> <?php echo $news['title']; ?></h3>
<?php
echo $news['body'];
}
echo "<br/><br/><br/>";
echo $lang['pages'] . ': ';
while($order = mysql_fetch_array($query)) {
if($f%7==0) {
echo "<a href='index.php?start=$d'>$g</a>";
$g++;
}
$d++;
$f++;
}
?>
</div>
</div>
<?php
include_once('inc/footer.php');
}
else {
include_once('inc/offline_header.php');
include_once('lib/stats_func.php');
?>
<div id="right_menu">
<?php include_once('inc/sidebar_statistics.php'); ?>
<br/>
<?php include_once('inc/sidebar_follow.php'); ?>
</div>
<div id="content">
<div class="text">
<br/>
<?php echo $lang['welcome']; ?>
<br/><br/>
<?php
if (isset($_POST['submit'])) {
$username = $_POST ['username'];
$password = $_POST ['password'];
$username = strip_tags ($username);
$password = md5 ($password);
mysql_real_escape_string($username);
$query = mysql_query ("SELECT id FROM users WHERE username='$username' AND password='$password'")
or die ("Couldn't connect to the do database.") ;
$result = mysql_fetch_array($query);
if($result) {
$_SESSION['username'] = $username;
header('Location: index.php');
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else {
$ip=$_SERVER['REMOTE_ADDR'];
}
$time = time();
mysql_query ("INSERT into logins (userid, time, ip)
VALUES ('$result[id]', '$time', '$ip')")
or die ("Couldn't connect to the database.");
}
else {
echo $lang['login_error'];
}
echo '<br/><br/>';
}
?>
<h2 class="hr"><?php echo $lang['about']; ?></h2>
<?php echo $lang['intro']; ?>
</div>
</div>
<?php
}
include_once('inc/footer.php');
?>
【问题讨论】:
-
这是这里最常被问到的问题,而且总是相同的原因。提问前请search。
-
@deceze 请在关闭前阅读。据我了解,他知道问题出在哪里。他在问最好的处理方法。因此,如果您有类似的问题,请分享,但不要链接一般的“标头已发送”问题,因为它们没有实际用处。
-
@Alin 答案总是一样的:不要在输出内容后开始会话。这个问题已经以几乎所有可能的形式回答了很多次。
-
@deceze 我确定之前已经回答过了,但请提供样本。和“输出内容后不要开始会话”。至少在他的情况下,可能并不像听起来那么容易。
-
@Alin:不在乎。如果 OP 懒得使用搜索,我为什么要搜索一个不错的副本?另外,您是否对此表示赞同?
标签: php