我正在尝试解决PHP的问题,但我找不到我的错误。如果有人可以帮助我,请写一个答案。
PHP发送以下错误消息:
[26-Feb-2014 03:00:46 Europe/Berlin] PHP Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/PressIn_21022014/includes/head.php:2) in /Applications/MAMP/htdocs/PressIn_21022014/recap_commande.php on line 41
点击valider_commande
:
<?php
session_start();
if(isset($_SESSION['auth']) && $_SESSION['auth'] == true){
$document = basename(__FILE__);
$titre = "Espace Membre";
include("includes/head.php");
?>
<div class="background col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="container top">
<div class="elements">
<form id="form_top_ten" method="POST" action="recap_commande.php">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="commande_top_ten">
<div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"><h4>Veste</h4></div>
<img src="img/icone_veste.svg" />
<button id="moins_veste" type="button" class="btn-moins btn-circle btn-mini"><i class="glyphicon-minus"></i> </button>
<span class="quantite" id="top_ten_nb_veste">1</span>
<button id="plus_veste" type="button" class="btn-plus btn-circle btn-mini"><i class="glyphicon-plus"></i> </button>
<div class="prix"><span class="prix_pantalon"> 10</span> €</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="commande_top_ten">
<div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"><h4>Pantalon</h4></div>
<img src="img/icone_pant.svg" />
<button id="moins_pantalon" type="button" class="btn-moins btn-circle btn-mini"><i class="glyphicon-minus"></i> </button>
<span class="quantite" id="top_ten_nb_pantalon">1</span>
<button id="plus_pantalon" type="button" class="btn-plus btn-circle btn-mini"><i class="glyphicon-plus"></i> </button>
<div class="prix"><span class="prix_pantalon"> 10</span> €</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="commande_top_ten">
<div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"><h4>Chemise</h4></div>
<img src="img/icone_chemise.svg" />
<button id="moins_chemise" type="button" class="btn-moins btn-circle btn-mini"><i class="glyphicon-minus"></i> </button>
<span class="quantite" id="top_ten_nb_chemise">1</span>
<button id="plus_chemise" type="button" class="btn-plus btn-circle btn-mini"><i class="glyphicon-plus"></i> </button>
<div class="prix"><span class="prix_pantalon"> 10</span> € </div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="commande_top_ten">
<div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"><h4>Robe</h4></div>
<img src="img/icone_robe.svg" />
<button id="moins_robe" type="button" class="btn-moins btn-circle btn-mini"><i class="glyphicon-minus"></i> </button>
<span class="quantite" id="top_ten_nb_robe">1</span>
<button id="plus_robe" type="button" class="btn-plus btn-circle btn-mini"><i class="glyphicon-plus"></i> </button>
<div class="prix"><span class="prix_pantalon"> 10</span> €</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="commande_top_ten">
<div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"><h4>Manteau</h4></div>
<img src="img/icone_manteau.svg" />
<button id="moins_manteau" type="button" class="btn-moins btn-circle btn-mini"><i class="glyphicon-minus"></i> </button>
<span class="quantite" id="top_ten_nb_manteau">1</span>
<button id="plus_manteau" type="button" class="btn-plus btn-circle btn-mini"><i class="glyphicon-plus"></i> </button>
<div class="prix"><span class="prix_pantalon"> 10</span> € </div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="commande_top_ten">
<div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"><h4>Veste</h4></div>
<img src="img/icone_pant.svg" />
<button type="button" class="btn-moins btn-circle btn-mini"><i class="glyphicon-minus"></i> </button>
<span class="quantite" id="top_ten_nb_veste">1</span>
<button type="button" class="btn-plus btn-circle btn-mini"><i class="glyphicon-plus"></i> </button>
<div class="prix"><span class="prix_pantalon"> 10</span> €</div>
</div>
</div>
</div>
<div class="row">
<div class="row col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="commande_top_ten">
<div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"><h4>Pull</h4></div>
<img src="img/icone_pull.svg" />
<button id="moins_pull" type="button" class="btn-moins btn-circle btn-mini"><i class="glyphicon-minus"></i> </button>
<span class="quantite" id="top_ten_nb_pull">1</span>
<button id="plus_pull" type="button" class="btn-plus btn-circle btn-mini"><i class="glyphicon-plus"></i> </button>
<div class="prix"><span class="prix_pantalon"> 10</span> €</div>
</div>
</div>
<div class="row col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="commande_top_ten">
<div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"><h4>Jupe</h4></div>
<img src="img/icone_jupe.svg" />
<button id="moins_jupe" type="button" class="btn-moins btn-circle btn-mini"><i class="glyphicon-minus"></i> </button>
<span class="quantite" id="top_ten_nb_jupe">1</span>
<button id="plus_jupe" type="button" class="btn-plus btn-circle btn-mini"><i class="glyphicon-plus"></i> </button>
<div class="prix"><span class="prix_pantalon"> 10</span> €</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="commande_top_ten">
<div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"><h4>Draps</h4></div>
<img src="img/icone_drap.svg" />
<button type="moins_drap" class="btn-moins btn-circle btn-mini"><i class="glyphicon-minus"></i> </button>
<span class="quantite" id="top_ten_nb_drap">1</span>
<button type="plus_drap" class="btn-plus btn-circle btn-mini"><i class="glyphicon-plus"></i> </button>
<div class="prix"><span class="prix_drap"> 10</span> €</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="commande_top_ten">
<div class="col-xs-3 col-sm-4 col-md-4 col-lg-3"><h4>Chemise</h4></div>
<img src="img/icone_chemisepliee.svg" />
<button type="moins_drap" class="btn-moins btn-circle btn-mini"><i class="glyphicon-minus"></i> </button>
<span class="quantite" id="top_ten_nb_drap">1</span>
<button type="plus_drap" class="btn-plus btn-circle btn-mini"><i class="glyphicon-plus"></i> </button>
<div class="prix"><span class="prix_pantalon"> 10</span> €</div>
</div>
</div>
</div>
<button type ="submit" class="btn_valider btn btn-danger col-xs-9 col-sm-6 col-md-6 col-lg-4" name="valider_commande" value="valider_commande"><i class="glyphicon glyphicon-shopping-cart"></i>Valider commande (' .$prix_total. ' euros)</button>
</form>
</div>
</div>
<?php
if (!empty($_SESSION['form_top_ten'])){
$nb_articles = sizeof($_SESSION['commande_top_ten']);
$prix_total = 0;
for ($i=0;$i<$nb_articles;$i++){
$prix_total += $_SESSION['commande_top_ten'][$i]['prix'];
}
}
?>
</div>
<?php
}
else{
header('Location:auth_form.php');
}
?>
这是 head.php 第2行:
<head>
**<title>E-Pressing - <?php echo $titre; ?></title>**
<link href="css/bootstrap.css" rel="stylesheet">
<meta charset="UTF-8">
<link href="css/business-frontpage.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Poiret+One' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
感谢您的帮助!
答案 0 :(得分:2)
在发送任何实际输出之前,必须通过普通HTML标记,文件中的空行或PHP来调用header()。使用include或require,函数或其他文件访问函数读取代码是一个非常常见的错误,并且在调用header()之前输出空格或空行。使用单个PHP / HTML文件时存在同样的问题。
<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>
答案 1 :(得分:1)
在以下任一行之前,您不能有空格:
session_start();
header('Location:auth_form.php');
你也可以通过在PHP脚本的最开头放置ob_start()
来“修复”这个问题,以便为你的内容启用输出缓冲(只有你别无选择才能这样做)
答案 2 :(得分:0)
该错误表示您在致电session_start
之前已在某处输出。你需要确保它是你打电话的第一件事(或尽可能接近它)