我有下面的脚本来检查用户是否是我的粉丝页面。如果是,他们将被重定向到另一页。如果没有,他们会在继续之前显示类似于该页面的框。
脚本有时可以工作,但有时却不能。我希望这与header()有问题,因为它有500内部服务器错误。但是,我已经把ob_start()。不应该解决问题吗?
<?
ob_start();
require_once('../../src/facebook.php');
$app_id = "APP_ID";
$app_secret = "APP_SECRET";
// Init facebook api.
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => false,
));
//Facebook Authentication part
$user_id = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'publish_stream, user_likes'
)
);
if (!$user_id) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
$likes = $facebook->api("/me/likes/PAGE_ID");
if( !empty($likes['data']) ){
ob_end_clean();
header ('location: xyz.php'); //if is a fan, redirect to xyz.php
exit;
} else {
continue; //if not a fan, show below html code
}
?>
<HTML>
.
.
Please like page first
.
.
</HTML>