我使用PHP SDK并按照示例操作。 https://github.com/facebook/php-sdk
当我使用Facebook登录并授予访问权限时,该页面将重定向到我当前的页面,但该网址包含state
和code
。如何避免显示这些参数?
代码如下:
"oauth.php":
<?php
require 'sdk/facebook.php';
$facebook = new Facebook(array(XXX,XXX));
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl($params);
}
?>
+++++++++++++++++++
"index.php":
<?php include 'oauth.php'; ?>
<!DOCTYPE html>
<html>
<head></head>
<body>
<div>
<?php if ($user): ?>
<img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
<?php else: ?>
<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
<?php endif ?>
</div>
</body>
</html>
答案 0 :(得分:1)
尝试在代码末尾添加标题(验证后)
header('Location:'.$currentPage);