本文介绍了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错误日志文件中得到错误:
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
推荐答案p>代码中的东西在调用setcookie之前会输出一些东西。它可以是调试消息。或者甚至在打开<?php标记之前的空行。
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.
更多推荐
FB API Cookie标头错误
发布评论