我的应用程序中出现以下错误,要求用户使用Facebook帐户登录: 警告:session_start()[function.session-start]:无法发送会话cookie - 已在第37行的XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX / lib / facebook.php中发送的标题(输出从XXXXXXXXXXXXXXXXXXXXXXXXXXXXX / fblogin1.php:4开始)
警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 第37行的XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX / lib / facebook.php中已发送的标头(输出从XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX / fblogin1.php:4开始)
我不知道为什么会出现这个错误,尽管我在phpcloud.com上托管我的应用程序时没有出现这个错误
这是fblogin1.php的代码
<?php
$id=$_GET['id'];
include('lib/db.php');
require 'lib/facebook.php';
require 'lib/fbconfig.php';
// Connection...
$user = $facebook->getUser();
if ($user)
{
$logoutUrl = $facebook->getLogoutUrl();
try {
$userdata = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
$_SESSION['facebook']=$_SESSION;
$_SESSION['userdata'] = $userdata;
$_SESSION['logout'] = $logoutUrl;
header("Location: home.php?id=$id");
}
else
{
$loginUrl = $facebook->getLoginUrl(array( 'scope' => 'user_about_me,user_activities,user_birthday,user_checkins,user_education_history,user_events,user_groups,user_hometown,user_interests,user_likes,user_location,user_notes,user_online_presence,user_photo_video_tags,user_photos,user_relationships,user_relationship_details,user_religion_politics,user_status,user_videos,user_website,user_work_history,email,read_friendlists,read_insights,read_mailbox,read_requests,read_stream,xmpp_login,ads_management,create_event,manage_friendlists,manage_notifications,offline_access,publish_checkins,publish_stream,rsvp_event,sms,publish_actions,manage_pages'
));
echo '<div class="style1"><a target="_top" href="'.$loginUrl.'"><img src="facebook.png" title="Login with Facebook" /></a></div>';
}
?>
这是facebook.php代码:
<?php
ob_start();
?>
<?php
require_once "base_facebook.php";
class Facebook extends BaseFacebook
{
public function __construct($config) {
if (!session_id()) {
session_start();
}
parent::__construct($config);
}
protected static $kSupportedKeys =
array('state', 'code', 'access_token', 'user_id');
protected function setPersistentData($key, $value) {
if (!in_array($key, self::$kSupportedKeys)) {
self::errorLog('Unsupported key passed to setPersistentData.');
return;
}
$session_var_name = $this->constructSessionVariableName($key);
$_SESSION[$session_var_name] = $value;
}
protected function getPersistentData($key, $default = false) {
if (!in_array($key, self::$kSupportedKeys)) {
self::errorLog('Unsupported key passed to getPersistentData.');
return $default;
}
$session_var_name = $this->constructSessionVariableName($key);
return isset($_SESSION[$session_var_name]) ?
$_SESSION[$session_var_name] : $default;
}
protected function clearPersistentData($key) {
if (!in_array($key, self::$kSupportedKeys)) {
self::errorLog('Unsupported key passed to clearPersistentData.');
return;
}
$session_var_name = $this->constructSessionVariableName($key);
unset($_SESSION[$session_var_name]);
}
protected function clearAllPersistentData() {
foreach (self::$kSupportedKeys as $key) {
$this->clearPersistentData($key);
}
}
protected function constructSessionVariableName($key) {
return implode('_', array('fb',
$this->getAppId(),
$key));
}
}
?>
我在这篇文章(What is output buffering?)中找到了一个主要线程,它声明输出缓冲是解决此类问题的方法。如果是的话,我应该在哪里添加它?在show.php或facebook.php中如何添加它?
注意:我在开始时添加了
这到最后
但这对我不起作用
答案 0 :(得分:0)
确保你的'lib / facebook.php'没有向屏幕写任何输出...没有echo命令等。错误告诉你的是在header()之前没有任何东西可以写入发送。它也告诉你在第37行的Facebook.php中写了一些东西。