DrXCheng
DrXCheng

Reputation: 4132

remove parameters from Facebook authentication redirect

I use the PHP SDK and follow the example. https://github.com/facebook/php-sdk

When I log in with Facebook and grant access, the page will redirect to my current page, but the url contains state and code. How to avoid displaying these parameters?

code is as follows:

"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>

Upvotes: 1

Views: 696

Answers (1)

Shpat
Shpat

Reputation: 502

try adding a header at the end of the code (after authentication)

   header('Location:'.$currentPage);

Upvotes: 1

Related Questions