[英]Issues with sessions on Facebook PHP SDK
我想在我的网站按钮中使onclick
会在用户Facebook墙上发布一条消息。 我从网站上的php页面调用AJAX脚本,该脚本将_POST中的消息发送到带有Facebook代码的php文件中。
运行我的php文件时出现此错误:
警告:session_start()[function.session-start]:无法发送会话缓存限制器-在/ home / user / public_html / fb中已发送的标头(输出从/home/user/public_html/fb/index.php:1开始) /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);
}
为什么会出现错误?
如果这是您的全部代码,则它看起来像会话实例之前包含的文件发送标头中的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.