我有几个子域网站,我希望每个都连接到 Facebook。
我已经为主域创建了我的 fb 应用程序,它适用于它。
在每个子域中,我使用此链接进行连接(由 ajax 调用编写):
<?php
echo "<a href=\"https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=myID
&scope=email,publish_stream,status_update&redirect_uri=http://www.mydomain.com/fbConnect.php?ref=".$_SERVER['HTTP_REFERER']."\">
Connect with Facebook
</a>";
?>
我的 fbConnect.php
<?php
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); // Hack IE for POST params...
header("Cache-Control: no-cache");
header("Pragma: no-cache");
session_set_cookie_params(0, '/', '.mydomain.com', false); // If session is lost with subdomains...
session_start();
require('/home/....../facebook.php');
$facebook = new Facebook(array(
'appId' => 'myid',// changed for the example
'secret' => 'mysecret', // same
'cookie' => true,
));
$user = null;
$loginUrl=$facebook->getLoginUrl(
array(
'canvas' => 0,
'scope' => 'email,publish_stream,user_location'
)
);
$logoutUrl = $facebook->getLogoutUrl();
$user=$facebook->getUser();
if(!$user) echo "<script>top.location.href='".$login_url."'</script>";
if ($user) {
echo "Ok";
$user_profile = $facebook->api('/me');
$userInfo = $facebook->api("/$user");
$_SESSION['fb_id']=$userInfo['id'];
// Some stuff...
echo "<script type='text/javascript'>top.location.href = '".$_GET['ref']."';</script>";
}
?>
范围、连接和重定向都在工作,但我无法$_SESSION['fb_id']
在$_GET['ref']
页面中返回……但是 session_id() 是一样的!