0
我有以下代碼:FB API cookie頭錯誤
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.
請幫我解決這個問題。用戶體驗的結果是,在我登錄後,頁面需要重新加載才能真正登錄。 感謝
沒有額外的行。甚至嘗試了dos2unix,以確保沒有額外的空間/行 –
然後刪除二進制搜索方式的行,找出引入此錯誤的違規行。從setcookie開始('loggedUserName','',time() - 3600);並看看它是否可以獨立運作。 –