2010-01-01 3 views
0

나는 이상한 오류를 생성하는 facebook 앱을 만들고 있습니다. 다음 내가 직면하고있는 오류입니다 :의 index.php에서facebook app의 PHP 헤더 오류

Warning: Cannot modify header information - headers already sent by (output started at /home/amitver/public_html/roadies/index.php:2) in /home/amitver/public_html/roadies/facebook.php on line 395 

Warning: Cannot modify header information - headers already sent by (output started at /home/amitver/public_html/roadies/index.php:2) in /home/amitver/public_html/roadies/facebook.php on line 395 

Warning: Cannot modify header information - headers already sent by (output started at /home/amitver/public_html/roadies/index.php:2) in /home/amitver/public_html/roadies/facebook.php on line 395 

Warning: Cannot modify header information - headers already sent by (output started at /home/amitver/public_html/roadies/index.php:2) in /home/amitver/public_html/roadies/facebook.php on line 399 

처음 몇 줄 수 있습니다 facebook.php에

<?php 

require_once 'facebook.php'; 
//facebook init 
    $appapikey = '...'; 
    $appsecret = '...'; 
    $facebook = new Facebook($appapikey, $appsecret); 
    $user_id = $facebook->require_login(); 


    $userInfo = $facebook->api_client->users_getInfo($user_id, array('name')); 
    $name = $userInfo[0]['name']; 

    //$useruidname = $facebook->api_client->fql_query("SELECT name FROM user WHERE uid='$user_id'"); 

    // Greet the currently logged-in user! 
    echo 'Hello, '.$name; 

?> 

라인 394-400은 다음과 같습니다

foreach ($cookies as $name => $val) { 
    setcookie($this->api_key . '_' . $name, $val, (int)$expires, '', $this->base_domain); 
    $_COOKIE[$this->api_key . '_' . $name] = $val; 
} 
$sig = self::generate_sig($cookies, $this->secret); 
setcookie($this->api_key, $sig, (int)$expires, '', $this->base_domain); 
$_COOKIE[$this->api_key] = $sig; 

나를 해결할 수있는 사람이 있습니까?

답변

2

아마도 setcookie 호출 전에 출력되고있는 index.php의 맨 위에있는 개행 문자입니다.

+0

당신이 옳았습니다. amit

0

포함하고있는 파일의 공백을 확인하십시오. 단지 하나의 ""PHP는 출력을 사용자 에이전트 (브라우저)에 보내고 더 이상 쿠키를 변경하거나 header() 데이터를 보낼 수 없습니다.

그 오류는 index.php 2 번 줄 (필수)이 보내지는 것을 나타냅니다. 그래서 include에 어떤 것이 출력되는지, 또는 파일에 facebook.php 파일의 끝에 공백/공백이 포함되어 있는지 확인하십시오.

1

이상한 오류에 대해서는 꽤나 간단합니다. 이미 출력을 보내기 시작 했으므로 맞춤 헤더를 보낼 수 없습니다. 출력을 클라이언트에 보내면 PHP는 먼저 헤더를 보내야합니다. 헤더가 전송되면 변경할 수 없습니다. 공백 문자를 보내거나 데이터를 반향 출력하거나 Set-Cookie 헤더를 조기에 보내고있는 것 같습니다. 헤더를 보내려면 먼저 목록이나 문자열에 헤더를 만들어야하며 일반적으로 내용을 그대로 유지해야합니다. 모든 헤더가 전송 된 후까지 출력 전송을 지연시키는 한 가지 방법은 출력 스트림을 캡처하는 것입니다. 좋아요 :

ob_start(); 

echo 'Hello world'; 

$output = ob_get_contents(); 

ob_end_clean(); 

물론이 문제는 실제로 빈 줄이지만 문제가되지는 않습니다.

+0

이것은 실제로 내 문제를 고쳤습니다. 감사합니다. – Arda