我想在我的网站按钮中制作onclick
将在用户 facebook 墙上发布消息的按钮。我从我网站中的 php 页面调用 AJAX 脚本,该脚本将 _POST 中的消息发送到带有 facebook 代码的 php 文件。
运行我的 php 文件时出现此错误:
警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送(输出开始于 /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);
}
为什么会出现错误?