我正在建立一个Facebook应用程序,它以某种方式产生这些奇怪的错误。 以下是我所面临的错误:
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
index.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;
?>
facebook.php中的第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;
有人可以帮我解决这个问题吗?
答案 0 :(得分:2)
答案 1 :(得分:1)
关于这个奇怪的错误,它非常简单。它表示您已经开始发送输出,因此您无法发送自定义标头。当您将输出发送到客户端时,PHP必须首先发送标头。标头发送后,您无法更改它们。看起来你要么发送空格或回送数据,要么过早地发送Set-Cookie标头。您应该在发送之前将标头构建为列表或字符串,通常您也会对内容执行相同的操作。在发送所有标头之后延迟发送输出的一种方法是捕获输出流。像这样:
ob_start();
echo 'Hello world';
$output = ob_get_contents();
ob_end_clean();
当然,你的问题实际上是一个空白,但这样做你不会有这个问题。
答案 2 :(得分:0)
检查您所包含的任何文件中的空白区域。只需一个“”,PHP就会将该输出发送给用户代理(浏览器),您无法再执行更改cookie或发送header()
数据等标题。
该错误表明index.php第2行(require)导致发送某些内容。因此,请检查是否在该include中输出了任何内容,或者该文件在facebook.php文件末尾包含空白行/空格。