duanmei1536 2018-04-09 12:58
浏览 79
已采纳

无法修改已由输出发送的标头信息标头

Delete image than redirect the page with query string i add query string with header but its not working Header not working

Error

headers already sent by output started at sidebar.php in delete.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 page check if page exist than load the page sidebar included in index page 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>
  • 写回答

1条回答 默认 最新

  • dqd22496 2018-04-09 13:30
    关注

    You are getting this error because you are already outputting content before setting a header.

    If your include("delete.php"); is going to redirect then you will need to perform this before outputting content.

    try...

    // 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>
    

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数据库获取信息反馈出错,直接查询了ref字段并且还使用了User文档的_id而不是自己的
  • ¥15 将安全信息用到以下对象时发生以下错误:c:dumpstack.log.tmp 另一个程序正在使用此文件,因此无法访问
  • ¥15 速度位置规划实现精确定位的问题
  • ¥15 代码问题:df = pd.read_excel('c:\User\18343\Desktop\wpsdata.xlxs')路径读不到
  • ¥15 为什么视频算法现在全是动作识别?
  • ¥15 编写一段matlab代码
  • ¥15 用Python做岩石类别鉴定软件
  • ¥15 关于调取、提交更新数据库记录的问题
  • ¥15 之前删了盘从下vs2022遇见这个问题 搞了一整天了
  • ¥15 从Freecad中宏下载的DesignSPHysics,出现如下问题是什么原因导致的(语言-python)