我有以下代码:
require '../lib/facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => '143944345745133',
'secret' => 'xxxxxxxx',
'cookie' => true,
));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$user = 0;
}
}
if ($user) {
setcookie('loggedUserId', $user, time()+36000);
setcookie('loggedUserName', $user_profile['name'], time()+36000);
} else {
setcookie('loggedUserId', '', time()-3600);
setcookie('loggedUserName', '', time()-3600);
}
我在php错误日志文件中收到错误:
[17-Dec-2012 06:11:34 UTC] There exists a cookie that we wanted to clear that we
couldn't clear because headers was already sent. Make sure to do the
first API call before outputing anything.
请帮我修理一下。结果用户体验是,在我登录后,需要重新加载页面才能实际登录。 感谢
答案 0 :(得分:0)
代码中的某些内容在调用setcookie之前输出了一些内容。它可能是一个调试消息。甚至在打开<?php标签之前的空行。