Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook PHP SDK-即使从Facebook注销,用户仍显示为已登录web应用程序_Php_Facebook_Sdk_Facebook Php Sdk_Logout - Fatal编程技术网

Facebook PHP SDK-即使从Facebook注销,用户仍显示为已登录web应用程序

Facebook PHP SDK-即使从Facebook注销,用户仍显示为已登录web应用程序,php,facebook,sdk,facebook-php-sdk,logout,Php,Facebook,Sdk,Facebook Php Sdk,Logout,我正在为自己开发一个网站,以便为有兴趣加入健身挑战小组的人提供指导。为此,我决定使用Facebook作为我的群组通信平台。随后,我开始将Facebook登录纳入我的网站(www.fitnesschallenges.net),并将加入群组的Facebook用户映射到我站点中相应群组的数据库 我为我的网站使用的平台是Wordpress,为了让登录/注销功能作为Wordpress插件正常工作(通过创建介于脚本-fblogin.php和fblogout.php之间的脚本),我必须有点创造性。到目前为止,

我正在为自己开发一个网站,以便为有兴趣加入健身挑战小组的人提供指导。为此,我决定使用Facebook作为我的群组通信平台。随后,我开始将Facebook登录纳入我的网站(www.fitnesschallenges.net),并将加入群组的Facebook用户映射到我站点中相应群组的数据库

我为我的网站使用的平台是Wordpress,为了让登录/注销功能作为Wordpress插件正常工作(通过创建介于脚本-fblogin.php和fblogout.php之间的脚本),我必须有点创造性。到目前为止,一切似乎都正常运转,只有一个例外。。。当用户从Facebook注销时,我的网站会继续显示他们已登录

我已经为这个特殊的问题做了很多搜索,其中有些人也经历过同样的行为。我的搜索结果让我相信这与会话和/或建立身份验证令牌有关,但我是一个新手程序员,正在寻找这方面的一些方向

提前谢谢

userreg.php ` ?>`

fblogout.php

`
?>`

编辑:服务器端访问令牌和用户的实际facebook登录状态相互独立。在更好地理解您的问题之后,您要做的是查看用户的实际Facebook登录状态。实际上,从API获取用户数据并不存在问题。最好的解决方案是使用Facebook Javascript API和FB.getLoginStatus函数:

您可以将其放置在themes header.php文件中,或使用Wordpress过滤器将其插入到打开的
标记后:

<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function () {
        FB.init({
            appId: 'YOUR_APP_ID', // App ID
            channelUrl: 'channel.html', // Channel File
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
        });

        FB.getLoginStatus(function(response) {

            if (response.status === 'connected') {
                var uid = response.authResponse.userID;
                jQuery('#facebook_status').html('User is logged into Facebook and Fitnesschallenges.net app');
            } else if (response.status === 'not_authorized') {
                jQuery('#facebook_status').html('User is logged into Facebook but not Fitnesschallenges.net app');
            } else {
                jQuery('#facebook_status').html('User is not logged into Facebook');
            }
        });

    };

    // Load the SDK Asynchronously
    (function (d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    }(document));
</script>d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    }(document));
</script>

window.fbAsyninit=函数(){
FB.init({
appId:'你的应用程序ID',//应用程序ID
channelUrl:'channel.html',//频道文件
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
FB.getLoginStatus(函数(响应){
如果(response.status===“已连接”){
var uid=response.authResponse.userID;
jQuery(“#facebook_status”).html('用户登录facebook和Fitnesschallenges.net应用程序');
}else if(response.status===“未授权”){
jQuery(“#facebook_status”).html('用户已登录facebook,但未登录Fitnesschallenges.net应用');
}否则{
jQuery(“#facebook_状态”).html('用户未登录facebook');
}
});
};
//异步加载SDK
(职能(d){
var js,id='facebook jssdk',ref=d.getElementsByTagName('script')[0];
if(d.getElementById(id)){return;}
js=d.createElement('script');js.id=id;js.async=true;
js.src=“//connect.facebook.net/en_US/all.js”;
ref.parentNode.insertBefore(js,ref);
}(文件);
(d){
var js,id='facebook jssdk',ref=d.getElementsByTagName('script')[0];
if(d.getElementById(id)){return;}
js=d.createElement('script');js.id=id;js.async=true;
js.src=“//connect.facebook.net/en_US/all.js”;
ref.parentNode.insertBefore(js,ref);
}(文件);
然后将其放在页面中某个要更新状态的位置:

<div id="facebook_status"></div>


所以,如果我错了,请纠正我。。。但我觉得我做的和您在选项一中所说的完全一样(我只想使用服务器端解决方案)。在第一个文件userreg.php中,我通过返回一个带有登录链接的图像来处理FacebookApiException。现在的结果表明没有异常,随后返回注销(即使用户已经从Facebook注销)。我理解错了吗?对不起,我假设fblogin.php也被用于验证第一次没有“注册”的用户(不会被强迫再次验证FB应用),这就是问题所在。那么你是说在userreg.php中正确填充了
$user\u profile
?据我所知,是的。php文件是用于实际决定用户状态并显示输出的文件。如果用户从Facebook注销,但以某种方式登录到我的网站,那么userreg.php是唯一使用的文件。fblogin.php最常用作代理。之所以这样做,是因为我无法确定如何使用Wordpress短代码,否则将不会出现异常——或者出现异常的原因。如果用户已登录、授权,并且您可以获取他们的信息,那么该文件中有什么问题?我仍然认为您的问题在fblogin.php中,因为try-catch块永远不会有异常,因为您甚至没有在try块中执行任何Facebook SDK代码。。。。使用SDK。fblogout.php也是如此。在这两种情况下,我都是通过redirect_uri和params数组中的next变量向它们传递URL和重定向路径。
$config = array(
    'appId' => '################',
    'secret' => '################',
    'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
);

$ls = $_GET['ls'];
$site = $_GET['site'];
$pagepath = $_GET['pp'];
$final = $_GET['final'];

$facebook = new Facebook($config);
$params = array('next' => $ls . '?final=1&ls=' . $ls . '&site=' . $site . '&pp=' . $pagepath);
$logoutUrl = $facebook->getLogoutUrl($params);

if($final == 0){
    header("Location: " . $logoutUrl);
}

if($final == 1){
    $facebook -> destroySession();
    header("Location: " . $site . $pagepath);
}
<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function () {
        FB.init({
            appId: 'YOUR_APP_ID', // App ID
            channelUrl: 'channel.html', // Channel File
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
        });

        FB.getLoginStatus(function(response) {

            if (response.status === 'connected') {
                var uid = response.authResponse.userID;
                jQuery('#facebook_status').html('User is logged into Facebook and Fitnesschallenges.net app');
            } else if (response.status === 'not_authorized') {
                jQuery('#facebook_status').html('User is logged into Facebook but not Fitnesschallenges.net app');
            } else {
                jQuery('#facebook_status').html('User is not logged into Facebook');
            }
        });

    };

    // Load the SDK Asynchronously
    (function (d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    }(document));
</script>d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    }(document));
</script>
<div id="facebook_status"></div>