关于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");
}
?>

Use ob_start() at the top of PHP page;

you need to put an exit() or die() after the header function - otherwise the rest of the script will continue to execute.

The redirection can take a relative or absolute URL. The problem is with the space BEFORE the colon. Try it like this:

header("Location: adminIndex.php");
die();

The problem is that you have echo before your header function.

if(!$result){
  echo "error".mysql_error();
}

before your two header("Location:adminIndex.php"), your can't echo anything.