如果有人需要,这就是解决这个问题的方法。
facebook_data.php:
<?php
define('APP_ID', 'hereyourappid');
define('APP_API_KEY', 'hereyourappid');
define('APP_SECRET', 'hereyoursecretappid');
error_reporting(0) ;
$signed_request = parse_signed_request(@$_REQUEST['signed_request'], APP_SECRET);
defin
e('LIKED', @$signed_request['page']['liked']);
$app_data = $signed_request['page']['liked'];
$redirect = $signed_request['app_data']; /* HERE I DECLARE A VARIABLE
THAT GET THE PARAMETER I PASS VIA URL */
$fanGate=LIKED;
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = @explode('.', $signed_request);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
?>
现在在我的 fangate (index.php) 里面我做:
<?php
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
header("Set-Cookie: SIDNAME=ronty; path=/; secure");
header('Cache-Control: no-cache');
header('Pragma: no-cache');
@session_start();
include('includes/facebook_data.php.php');
$sezione='fangate';
$pagina = '';
?>
<?php if(!LIKED): ?>
<!DOCTYPE HTML>
<html>
<head>
<?php include("includes/head.php"); ?>
</style>
</head>
<body>
<?php include("includes/fb.php"); ?>
<div id="fangate">
<!-- your fangate -->
<?php include("includes/footer.php");?>
</div>
</body>
</html>
<?php
elseif($redirect == "gotopage"):
header('Location: page2.php');
else:
header('Location: homepage.php');
endif;
?>