问题
I have the following code:
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);
}
and I get the error in my php error log file:
[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.
Please help me fix it. The result user experience is that after I log in, the page needs to be reloaded to actually log in. Thanks
回答1:
Something in your code is outputting something before the call to setcookie. It could be a debug message. Or even an empty line before opening <?php tag.
来源:https://stackoverflow.com/questions/13910661/fb-api-cookie-header-error