这是错误:
警告:无法修改标头信息 - 标头已由第 16 行 C:\xampp\htdocs\newop\mainindex.php 中的(输出开始于 C:\xampp\htdocs\newop\template\header.php:80)发送
标题的第 80 行是这样的(它是单行,仅解包):
<div class="col-md-2 col-xs-2 device-select">
<a href="budget.php?device=2">
<img class="full-width" src="res/images/device2.jpg">
</img>
</a>
<center class="popular-devices">
<?php echo $lang['header_dropdown_string_2'];?>
</center>
</div>
...这是代码:
<?php
session_start();
if (!isset($_SESSION['user'])){ header("Location: index.php"); }
?>
<html>
<body>
<?php
include("template/head.php");
include("template/header.php");
include ("db_files/db.php");
$usermail = mysqli_real_escape_string($db, $_SESSION['user']);
$strSQL = "SELECT nivel FROM usuarios where email ='$usermail'";
$query = mysqli_query($db, $strSQL);
while ($result = mysqli_fetch_array($query)){
if ($result['nivel'] == 1 || $result['nivel'] == 2){
header("location: userlist:php");
}
}
$state = array(
1 => $lang['state_name_string_1'],
2 => $lang['state_name_string_2'],
3 => $lang['state_name_string_3'],
4 => $lang['state_name_string_4'],
);
?>
<div class="content container">
<div class="row no-margin no-padding">
<div class="col-md-2 hidden-sm hidden-xs">
<div class="mainuserimage">
<img class="full-width" src="res/images/users/user1.png"/>
</div>
<div>
<?php
$strSQL = "SELECT nombre, email, telefono FROM usuarios where email ='$usermail'";
$query = mysqli_query($db, $strSQL);
while ($result = mysqli_fetch_array($query)){
echo "<i class='glyphicon glyphicon-user'></i> ".$result['nombre']."<br>";
echo "<i class='glyphicon glyphicon-envelope'></i> ".$result['email']."<br>";
echo "<i class='glyphicon glyphicon-earphone'></i> ".$result['telefono']."<br>";
}
?>
</div>
</div>
<div class="col-md-10 col-xs-12">
<h3 class="main-title"><?php echo $lang['mainindex_string_1']; ?></h3><br>
<div class="row">
<div class="col-md-2 col-xs-3">
<p><?php echo $lang['mainindex_string_2']; ?></p>
</div>
<div class="col-md-2 col-xs-3">
<p><?php echo $lang['mainindex_string_3']; ?></p>
</div>
<div class="col-md-2 col-xs-3">
<p><?php echo $lang['mainindex_string_4']; ?></p>
</div>
<div class="col-md-2 hidden-sm hidden-xs">
<p><?php echo $lang['mainindex_string_5']; ?></p>
</div>
<div class="col-md-2 col-xs-3">
<p><?php echo $lang['mainindex_string_6']; ?></p>
</div>
<div class="col-md-2 hidden-sm hidden-xs">
<p><?php echo $lang['mainindex_string_7']; ?></p>
</div>
<?php
$strSQL = "SELECT id, marca, modelo, imei, descripcion_problema, problem, problem2, problem2_namees, estado, fecha_creacion FROM tickets, problem2 WHERE tickets.email = '$usermail' AND tickets.problem2 = problem2.problem2_id";
$query = mysqli_query($db, $strSQL);
while($result = mysqli_fetch_array($query)){ ?>
<div class="col-md-2 col-xs-3">
<p><a href="repairdetail.php?id=<?php echo $result['id']; ?>"><i class="glyphicon glyphicon-list-alt"></i></a> <?php echo $result['marca']; ?></p>
</div>
<div class="col-md-2 col-xs-3">
<p><?php echo $result['modelo']; ?></p>
</div>
<div class="col-md-2 col-xs-3">
<p><?php echo $result['imei']; ?></p>
</div>
<div class="col-md-2 hidden-sm hidden-xs">
<p><?php echo $result['problem2_namees']; ?></p>
</div>
<div class="col-md-2 col-xs-3">
<p><?php echo $state[$result['estado']]; ?></p>
</div>
<div class="col-md-2 hidden-sm hidden-xs">
<p><?php echo $result['fecha_creacion']; ?></p>
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
<?php
include("template/footer.php");
?>
</body>
</html>
移动方块:
之前:
有关错误的其他信息:
- headers already sent
一条消息
HTTP
由一个标头Header
和一个正文组成Body
,它们按此顺序发送到客户端Client
。发送时,Body
无法再发送Header
。header()
如果您在发送后尝试调用该函数HTML
,您将得到著名的错误:Cannot modify header information - headers already sent
.不仅header()函数修改
Header
了以下函数:在发送之前也会产生错误的其他示例
Header
:_<?php
?>_
HTML
,echo
,print
,var_dump()
....etc错误代码示例:
发生错误是因为您在修改标头之前发送了 html 输出,因此默认标头已经发送。
您可以通过在 header 命令之后移动 html 块来解决此问题。或者也使用
ob_start()
第一行代码中的函数。这将启动输出缓冲区缓存,并且在脚本完成之前不会发送标头。