我想在我的网站按钮中onclick
将在用户Facebook墙上发布消息。
我从我网站上的php页面调用一个AJAX脚本,该脚本使用facebook代码将_POST中的消息发送到php文件。
我在运行我的php文件时遇到此错误:
警告:session_start()[function.session-start]:无法发送 会话缓存限制器 - 已发送的标头(输出始于 /home/user/public_html/fb/index.php:1)in 第49行/home/user/public_html/fb/facebook.php
我的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 :(得分:0)
如果这是您的所有代码,它看起来像是在会话实例之前在包含文件中发送的标题。