Facebook上的会话问题PHP SDK

问题描述:

我想在我的网站中按钮onclick将在用户的Facebook墙上张贴消息。 我从我的网站中的PHP页面调用了一个AJAX脚本,它将_POST中的消息用facebook代码发送到php文件。Facebook上的会话问题PHP SDK

我得到这个错误,而运行我的PHP文件:

警告:在session_start()[function.session启动]:不能发送 会话缓存限制器 - 已经发送了头(输出开始 /home/user/public_html/fb/index.php:1)在 /home/user/public_html/fb/facebook.php上线49

我的PHP是这样的:

<?php 
include('../ilink.php'); //mysqli connection 

$fb_message=$_POST['fb_message']; 
$fb_description=$_POST['fb_description']; 
$fb_picture=$_POST['fb_picture']; 


require 'facebook.php'; 

// Create our Application instance. 
$facebook = new Facebook(array(
    'appId' => '--appid--', 
    'secret' => '--secret--', 
    'cookie' => true 
)); 

    $user = $facebook->getUser(); 

    if ($user) { 
     try { 
     // Proceed knowing you have a logged in user who's authenticated. 
     $user_profile = $facebook->api('/me'); 
     } catch (FacebookApiException $e) { 
     error_log($e); 
     $user = null; 
     } 
    } 

    // Login or logout url will be needed depending on current user state. 
    if ($user) { 
     $logoutUrl = $facebook->getLogoutUrl(); 
    } else { 
     $loginUrl = $facebook->getLoginUrl(); 
    } 

    $attachment = array('message' => $fb_message, 
      'name' => 'text', 
      'caption' => 'text', 
      'link' => 'http://www.domain.com', 
      'description' => $fb_description, 
      'picture' => $fb_picture, 
      'actions' => array(array('name'=>'text', 
           'link' => 'http://www.domain.com'),) 
      ); 

    $result = $facebook->api('/me/feed/','post',$attachment); 
?> 

我的AJAX脚本:

function fb_post(fb_message,fb_description,fb_picture,redirect){ 
     var xmlhttp; 
     if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari 
      xmlhttp=new XMLHttpRequest(); 
     } 
     else{// code for IE6, IE5 
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
     } 
     xmlhttp.onreadystatechange=function(){ 
      if (xmlhttp.readyState==4 && xmlhttp.status==200){ 

       document.location.href =redirect;    
      } 
     } 

     var q="fb_message="+fb_message+"&fb_description="+fb_description+"&fb_picture="+fb_picture; 
     xmlhttp.open("POST","/fb/index.php",true); 
     xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
     xmlhttp.send(q); 
} 

为什么错误出现在哪里?

+0

由于当身体部位发送要求头部再次发送时出现此错误。请从页面顶部的所有文件中删除任何空间 – 2013-03-23 19:22:12

如果这是您的所有代码,它看起来像包含文件中的某些内容在会话实例之前发送了头文件。

+0

我在我的网站上的每个页面都有Session(用于用户登录)。 facebook.php上有会话。也许我需要以某种方式销毁会话? Rohit Kumar - 我没有空格。 – 2013-03-24 07:05:07

+0

你在每个页面上的含义是什么,你不必在每一页上开始会话,显示更多的代码。 – robinloop 2013-03-24 15:33:58

+0

我在每个页面中都包含(username.php)konwing谁是现在登录的用户,此页面以下列行开始: 2013-03-24 17:28:59