2012-06-05 3 views
1

저는 한 페이지에서 다른 페이지로 리디렉션하려고하는 PHP 프로젝트에서 헤더 (위치 : 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 
이미 include, include_once, requirerequire_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"); 
} 
?> 
+0

. : 위의 에코 때문일 수 있습니다. 헤더가 작동하지 않고 오류가 발생했습니다. – sephoy08

+0

문제는 헤더()를 설정하기 전에 내용을 에코하기 시작한 것입니다. 언급 된대로 @shatru로 ob_start하거나 헤더() 호출보다 먼저 텍스트를 에코하지 않도록 코드를 다시 조정하십시오. – Scuzzy

답변

0

PHP 페이지 상단에서 ob_start()를 사용하십시오.

0

헤더 기능 뒤에 exit() 또는 die()를 넣어야합니다. 그렇지 않으면 나머지 스크립트가 계속 실행됩니다.

리디렉션은 상대 URL 또는 절대 URL을 사용할 수 있습니다. 문제는 콜론 (colon) 이전의 공간입니다. 다음과 같이 시도하십시오.

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

감사합니다. –

0

문제는 헤더 기능 전에 에코가있는 것입니다.

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

두 개의 헤더 ("Location : adminIndex.php") 앞에는 아무 것도 울릴 수 없습니다.