我正在使用WordPress在Facebook上制作应用程序,一切都很好,我在应用程序的首页上,但当我尝试在Mozilla Firefox中访问我的应用程序的另一个页面的链接时显示空白页面,并且谷歌浏览器保留在首页。
有谁知道为什么会这样?有没有人遇到过这种行为?
我的下一个代码是我在WordPress根index.php中使用的,而不是首页index.php,用于在进入应用程序之前请求用户的权限:
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
session_start();
require 'src/facebook.php';
// LOGIN
$app_details = array('app_id' => 'secret',
'app_secret' => 'secret',
'page_link' => '//www.facebook.com/secret/'
);
$http = "http:";
if(isset($_SERVER['HTTPS']))
if (!empty($_SERVER['HTTPS'])) $http = "https:";
$facebook = new Facebook(array(
'appId' => $app_details['app_id'],
'secret' => $app_details['app_secret'],
'cookie' => true
));
$the_signed_request = $facebook->getSignedRequest();
if ($the_signed_request == null) {
header("Location: ".$http.$app_details['page_link']."app/".$app_details['app_id']);
}
if ( !isset($the_signed_request['user_id']) && !isset($the_signed_request['oauth_token']) ){
$loginUrl = $facebook->getLoginUrl(array('scope'=>'email'));
if (!isset($_SESSION['rejects'])) $_SESSION['refuzuri'] = 0;
else $_SESSION['rejects']++;
if ($_SESSION['rejects']>4) {
echo "This app works only if permissions are accepted.<br/>";
echo "To accept the permissions <a href='".$loginUrl."' target='_top'>click here</a>";
die();
}
echo( "<script>top.location.href='" . $loginUrl . "';</script>" );
}else{
try{
$access_token = $facebook->getAccessToken();
$user = $facebook->getUser();//userid
$userinfo = $facebook->api('/me?fields=id,name,email,gender,locale'); //for basic details
}catch (FacebookApiException $e) {
$user = null;
$userinfo = null;
}
$_SESSION['user']= $userinfo;
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
}
?>