我的应用程序中出现以下错误,要求用户使用facebook帐户登录:警告:session_start()[function.session-start]:无法发送会话cookie - 已经发送的标头(输出从XXXXXXXXXXXXXXXXXXXXXXXXXXXXX /开始show.php:4)在第37行的XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX / lib / facebook.php中
警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 在第37行的XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX / lib / facebook.php中已经发送的报头(输出从XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX / show.php:4开始)
我不知道为什么会出现这个错误,尽管我在phpcloud.com上托管我的应用程序时没有出现这个错误
以下是show.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
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));
}
}
?>
现在这里是fbconfig.php
<?php
//Facebook Application Configuration.
$facebook_appid='XXXXXXXXXXXXXXXXXXX';
$facebook_app_secret='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$facebook = new Facebook(array(
'appId' => $facebook_appid,
'secret' => $facebook_app_secret,
));
?>
我在这篇文章(什么是输出缓冲?)中找到了一个主要线程,它声明输出缓冲是解决这些问题的方法。如果是的话,我应该在哪里添加它?在show.php或facebook.php以及如何添加它?
答案 0 :(得分:-1)
请打开您在记事本中修改的php文件和另存为ANSI然后FTP回到服务器。解决!!!