簡體   English   中英

無法修改輸出已發送的標題信息標題

[英]Cannot modify header information headers already sent by output

刪除圖片而不是使用查詢字符串重定向頁面我添加了帶有標題的查詢字符串,但是它不起作用標題不起作用

錯誤

已由輸出發送的標頭從delete.php中的sidebar.php開始

Delete.php

if(!isset($_SESSION['admin_email'])){

echo "<script>window.open('login.php','_self')</script>";

}

else {

if(isset($_GET['delete'])){
$id = $_GET['delete'];
$page = $_GET['page'];
$image = $_GET['image'];
$section = $_GET['section'];
$delete_p_cat = "delete from $page where id='$id' AND section = '$section'";
$run_delete = mysqli_query($con,$delete_p_cat);

if($run_delete)
{
  header('Location: index.php?view&page='.$page.'&section='.$section);
  exit();
}
 }
} ?>

索引頁面檢查頁面是否存在,而不是加載索引頁面index.php中包含的頁面側邊欄

   <div id="wrapper">

   <?php include("includes/sidebar.php");  ?>

  <div id="page-wrapper">

   <div class="container-fluid">

   <?php

   if(isset($_GET['dashboard'])){

    include("dashboard.php");

   }
    if(isset($_GET['view'])){

    include("view.php");

   }
   if(isset($_GET['delete'])){

    include("delete.php");

   }

   </div>

   </div>

  </div>

之所以出現此錯誤,是因為在設置標題之前已經輸出了內容。

如果您的include("delete.php"); 要重定向,那么您需要在輸出內容之前執行此操作。

嘗試...

// before any output
if(!isset($_SESSION['admin_email']) && isset($_GET['delete'])){
    include("delete.php");
}
?>
<div id="wrapper">
<?php include("includes/sidebar.php");  ?>

<div id="page-wrapper">

<div class="container-fluid">

<?php

  if(isset($_GET['dashboard'])){
    include("dashboard.php");
  }
  if(isset($_GET['view'])){
    include("view.php");
  }
  if(isset($_GET['delete'])){
    // remove this from delete.php
    if(!isset($_SESSION['admin_email'])){
      // looking at it, this may also want to be at the top 
      // if you are checking for a 'logged in user'
      echo "<script>window.open('login.php','_self')</script>";
    }
  }
</div>

</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM