Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot send session cookie - headers already sent while requesting facebook API
    primarykey
    data
    text
    <p>I am getting the following error in my application that asks the user to login using facebook account : Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at XXXXXXXXXXXXXXXXXXXXXXXXXXXXX/show.php:4) in XXXXXXXXXXXXXXXXXXXXXXXXXXXXX/lib/facebook.php on line 37</p> <p>Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at XXXXXXXXXXXXXXXXXXXXXXXXXXXXX/show.php:4) in XXXXXXXXXXXXXXXXXXXXXXXXXXXXX/lib/facebook.php on line 37</p> <p>I don't know why this error is shown in spite of the face that it does not appear when I was hosting my app on phpcloud.com</p> <p>Here is the code of the show.php</p> <pre><code>&lt;?php $id=$_GET['id']; include('lib/db.php'); require 'lib/facebook.php'; require 'lib/fbconfig.php'; // Connection... $user = $facebook-&gt;getUser(); if ($user) { $logoutUrl = $facebook-&gt;getLogoutUrl(); try { $userdata = $facebook-&gt;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-&gt;getLoginUrl(array( 'scope' =&gt; '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 '&lt;div class="style1"&gt;&lt;a target="_top" href="'.$loginUrl.'"&gt;&lt;img src="facebook.png" title="Login with Facebook" /&gt;&lt;/a&gt;&lt;/div&gt;'; } ?&gt; </code></pre> <p>Here is the facebook.php code :</p> <pre><code> &lt;?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-&gt;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-&gt;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-&gt;constructSessionVariableName($key); unset($_SESSION[$session_var_name]); } protected function clearAllPersistentData() { foreach (self::$kSupportedKeys as $key) { $this-&gt;clearPersistentData($key); } } protected function constructSessionVariableName($key) { return implode('_', array('fb', $this-&gt;getAppId(), $key)); } } ?&gt; </code></pre> <p>Now here is the fbconfig.php</p> <pre><code> &lt;?php //Facebook Application Configuration. $facebook_appid='XXXXXXXXXXXXXXXXXXX'; $facebook_app_secret='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; $facebook = new Facebook(array( 'appId' =&gt; $facebook_appid, 'secret' =&gt; $facebook_app_secret, )); ?&gt; </code></pre> <p>I have found a leading thread in this post (What is Output Buffering?) that states that outputbuffering is a solution to such problems. If so, where shall I add it ? in show.php or facebook.php and how to add it ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload