dousao2186 2012-06-05 05:06
浏览 18

关于PHP中的头错误

I am working on a PHP project where I am trying to redirect from one page to another, using header (Location:something.php). It's working fine on the local machine but when uploaded to the server, the following error occurs:

Warning: Cannot modify header information - headers already sent by (output started at /homepages/4/d404449574/htdocs/yellowandred_in/newTest/editHome.php:15) in /homepages/4/d404449574/htdocs/yellowandred_in/newTest/editHome.php on line 43

I already tried with include, include_once, require and require_once but it's giving other errors like:

Cannot redeclare logged_in() (previously declared in C:\wamp\www\ynrNewVersion-1\editHome.php:3) in C:\wamp\www\ynrNewVersion-1\adminIndex.php on line 5

My code

<?php
session_start();
function logged_in() {
  return isset($_SESSION['username']);
}

function confirm_logged_in() {
  if (!logged_in()) {
    include "error404.php";
    exit;
  }
}

confirm_logged_in();
require_once("connection.php");

$query="select * from home";
$homeInfo = mysql_query($query, $connection);
$result = mysql_fetch_array($homeInfo);

$content = $result['content'];
$rssFeeds = $result['rssFeeds'];
$message = "";
if(isset($_POST['submit'])){
  $content = $_POST['content'];
  $rssFeeds = $_POST['rssFeeds'];
  if($content == "" || $rssFeeds == ""){
    $message = "Please enter into all the fields";
  } else {
    $query = "UPDATE home SET content='$content',rssFeeds='$rssFeeds' WHERE id=1 LIMIT 1";
    $result = mysql_query($query,$connection);
    if(!$result){
      echo "error".mysql_error();
    }
    if ($result == 1) {
      header("Location:adminIndex.php");
    } else {
      $message = "Error Occurred";
    }
  }
}
if(isset($_POST['cancel'])){
  header("Location:adminIndex.php");
}
?>
  • 写回答

3条回答 默认 最新

  • doucitan2544 2012-06-05 05:09
    关注

    Use ob_start() at the top of PHP page;

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题