[英]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.