我想在我的網站中按鈕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);
}
爲什麼錯誤出現在哪裏?
由於當身體部位發送要求頭部再次發送時出現此錯誤。請從頁面頂部的所有文件中刪除任何空間 – 2013-03-23 19:22:12