Facebook 登录重定向 PHP/Javascript 不起作用


Facebook Login Redirect PHP/Javascript Not Working

我已经浏览了网站上的许多帖子,但仍然无法获得Facebook登录和重定向工作。当用户通过按下网页上的按钮通过Facebook登录时,我想自动将他们重定向到另一个网页,并通过URL传递他们的电子邮件和密码。不幸的是,我只能让它工作到当他们登录时,我必须手动重新加载页面才能通过刷新我的网页让他们进入重定向页面。我想知道是否有人可以发布有关如何执行此操作的代码?我尝试过很多东西。

<?php
 //uses the PHP SDK.  Download from https://github.com/facebook/php-sdk
 require 'facebook.php';
define('YOUR_APP_ID', 'xxxx');
$facebook = new Facebook(array(
    'appId'  => 'xxxx',
   'secret' => 'xxxx',
  ));   
?>
<div id="fb-root"></div>
<div id="user-info"></div>
     <div class="fb-login-button" style="position:absolute;top:800px;">Login with Facebook</div>


<script>
    window.fbAsyncInit = function() {
      FB.init({ appId: 'xxxx', 
            status: true, 
            cookie: true,
            xfbml: true,
            oauth: true});
  function updateButton(response) {
    var button = document.getElementById('fb-auth');
    if (response.authResponse) {
      //user is already logged in and connected
      var userInfo = document.getElementById('user-info');
      FB.api('/me', function(response) {
        userInfo.innerHTML = '<img src="https://graph.facebook.com/' 
      + response.id + '/picture">' + response.email;
        button.innerHTML = 'Logout';
             });
      button.onclick = function() {
        FB.logout(function(response) {
          var userInfo = document.getElementById('user-info');
          userInfo.innerHTML="";
    });
      };



} 

    else {
      //user is not connected to your app or logged out
      button.innerHTML = 'Login';
      button.onclick = function() {
        FB.login(function(response) {
      if (response.authResponse) {
            FB.api('/me', function(response) {
          var userInfo = document.getElementById('user-info');
          userInfo.innerHTML = 
                '<img src="https://graph.facebook.com/' 
            + response.id + '/picture" style="margin-right:5px"/>' 
            + response.name;

        });    
          } else {
            //user cancelled login or did not grant authorization
          }
        }, {scope:'email'});    
      }
    }
  }

  // run once with current status and whenever the status changes
  FB.getLoginStatus(updateButton);
  FB.Event.subscribe('auth.statusChange', updateButton);    
};
(function() {
  var e = document.createElement('script'); e.async = true;
  e.src = document.location.protocol 
    + '//connect.facebook.net/en_US/all.js';
  document.getElementById('fb-root').appendChild(e);
}());


</script>
<?php
   $uid = $facebook->getUser();
    if($uid != 0) {
        header("Location: signup.php");
      }   
    ?>

主要将header('Location')用于Facebook应用程序不起作用。

我假设代码的其余部分正在工作,因此唯一需要的更改是

$uid = $facebook->getUser();
if($uid != 0) {
    echo("<script> top.location.href='your-login-url'</script>");
    return;
}

希望这有帮助