1

ヘッダー (Location:something.php) を使用して、あるページから別のページにリダイレクトしようとしている PHP プロジェクトに取り組んでいます。ローカル マシンでは問題なく動作していますが、サーバーにアップロードすると、次のエラーが発生します。

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

includeinclude_once、 でrequire既に試しましたが、require_once次のような他のエラーが発生しています。

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

私のコード

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

3 に答える 3

0

問題は、ヘッダー関数の前にエコーがあることです。

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

2 つのヘッダー ("Location:adminIndex.php") の前では、何もエコーできません。

于 2012-06-05T05:24:08.927 に答える
0

PHP ページの上部で ob_start() を使用します。

于 2012-06-05T05:09:34.357 に答える
0

ヘッダー関数の後に exit() または die() を配置する必要があります。そうしないと、残りのスクリプトが引き続き実行されます。

リダイレクトには、相対 URL または絶対 URL を使用できます。問題は、コロンの前のスペースにあります。次のようにしてみてください。

header("Location: adminIndex.php");
die();
于 2012-06-05T05:10:19.460 に答える