Facebook Connect禁用自动登录 [英] Facebook Connect disable auto login

查看:153
本文介绍了Facebook Connect禁用自动登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整合了图形API的连接,但是如果我们登录到Facebook,我们将自动登录到Facebook连接的网站。是否有任何方式让用户点击fb登录,然后用户使用他们的fb帐户连接到该站点?

I integrated the graph api facebook connect but if we are login to facebook, we will automatically login to the site with facebook connect as well. Is there any way we let the user clicks on fb "Login" only then the user is connected to the site with their fb account?

现在用户自动登录该网站没有选择是否要使用他们的Facebook帐户。如果他们想从网站注销,他们需要从Facebook完全注销,然后他们可以使用Facebook连接从网站注销。

Now the user is automatically login to the site without the option to choose whether they would want to use their facebook account. If they want to logout from the site, they need to logout from facebook completely only then they can logout from the site with facebook connect as well.

任何人都可以帮助我或给一些提示如何去?
谢谢!

Anyone can help me or give some tips how to go about? Thank you!

推荐答案

我在最近的网站上遇到了同样的问题,并找到了一种方法来克服。我的解决方案允许用户已经在他们的计算机上登录到Facebook,但没有在我的网站上自动登录,然后他们可以登录Facebook登录按钮,最后当他们注销它不会将他们从他们的计算机上的Facebook登录,就在我的网站上(就像Digg和Facebook一样)。

I had this same problem on a recent website, and found a way to overcome it. My solution allowed a user to already be logged into facebook on their computer, yet not have it auto login on my website, then they can login with Facebook Login button and finally when they logout it won't log them out of Facebook on their computer, just on my website (much like Digg does with facebook).

要做到这一点,我使用的是 https://github.com/facebook/php-sdk/ 在PHP内检查是否有与用户和网站的活跃的Facebook会话(这将导致自动登录)。如果有,我不会回应自动登录代码:

To do it I was using https://github.com/facebook/php-sdk/ to check within PHP if there was an active facebook session with the user and the website (which would cause the auto login). If there was, I would not echo the auto login code:


  FB.init({ 
      appId   : '<?php echo $facebook->getAppId(); ?>',
      session : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it
      status  : true, // check login status
      cookie  : true, // enable cookies to allow the server to access the session
      xfbml   : true // parse XFBML
    });     
    FB.Event.subscribe('auth.login', function() {
      window.location = "process-login.php";
    });


,而只是渲染我自己的Facebook登录按钮,链接到process-login.php。

but instead just render my own facebook login button that would link to "process-login.php".

process-login.php将设置自定义$ _SESSION变量,告诉我的网站有人被记录(不管是通过我自己的系统还是通过Facebook),然后重新加载引用页面(使用$ _SERVER ['HTTP_REFERER']),现在将显示用户通过Facebook登录,因为我现在设置了自己的$ _SESSION变量。要登录(没有将它们从Facebook完全登录,只是我的网站),我只需要加载一个删除$ _SESSION变量的注销脚本。

process-login.php would set the custom $_SESSION variable that told my website someone was logged (whether via my own system, or via facebook), and then reload the referring page (using $_SERVER['HTTP_REFERER']) which would now display the user as logged in via Facebook since my own $_SESSION variable was now set. To log them out (without logging them out of Facebook entirely, just my website), I would just load a logout script that removed the $_SESSION variable.

该示例。 php(在github中的php-sdk中)对于找到我的解决方案非常有帮助,尽管我必须对它进行自定义,以使其能够与现有系统配合使用。至少帮助我看到如何使用PHP访问Facebook会话变量(在示例中存储在$ me中)。

The example.php (in the php-sdk on github) was very helpful at finding my solution, though I had to customise it significantly to make it work with my existing system. It at least helped me see how to access the facebook session variable in PHP (stored in $me in the example).

希望这可以帮助您,如果它仍然是一个问题,或者它在这种情况下帮助别人。

Hope this helps you if its still a problem, or that it helps someone else in this situation.

编辑:
结果我在罕见的场合仍然有一些自动登录的问题。要修复它,我删除了event.subscribe('auth.login'),并创建一个Facebook按钮,在订阅auth.login之前,调用以下函数来检查登录状态。这是功能:

Turns out I still had some issues with auto login on the rare occasion. To fix it I removed the event.subscribe('auth.login') and make a facebook button that called the following function to check login status before subscribing to the auth.login even. Here is the function:


  function check_login_session(){
        FB.getLoginStatus(function(r){
            if(r.session){
                window.location = '/process-login.php';
            }
            else{
                FB.Event.subscribe('auth.login', function(response) {
                    window.location = '/process-login.php';
                });
                FB.login();
            }
        });
    }`


这篇关于Facebook Connect禁用自动登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆