FB API Cookie Header Error

你。 提交于 2019-12-12 01:59:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!