简体   繁体   English

当用户使用Facebook进行连接时,无法从站点注销用户

[英]Cant logout users from site when they use connect via facebook

Ok i made a code where i connect the user to my database and then i set as login to that user, if the email is already in the database i just Login the user... 好的,我编写了一个代码,将用户连接到数据库,然后将其设置为该用户的登录名,如果电子邮件已经在数据库中,则只需登录该用户...

The problem is logout button is not working.. i have tried. 问题是注销按钮不起作用。

session_start(); 
session_destroy();

On the Logout, but as soon as is redirected to the index page, (i think is loged in again) 在登出时,但是一旦重定向到索引页面,(我认为是再次登录)

how can i avoid this.. 我如何避免这种情况..

EDIT: i dont want the user to be loged out from facebook. 编辑:我不希望用户从Facebook注销。 just loged out from my site 刚从我的网站注销

This is my code. 这是我的代码。

<?php
if ($userId) {
 //
 // already logged? show some data
 $userInfo = $facebook->api('/' + $userId);





 if (isset($userInfo['email']))

{ include "facebookregister.php"; } else { echo "no hay permisos de facebook"; }

} else {
 //
 // use javaascript api to open dialogue and perform
 // the facebook connect process by inserting the fb:login-button
 ?>
 <div id="fb-root"></div>
 <fb:login-button scope='email,user_birthday'></fb:login-button>
 <?php
}
?>
 <script>
 window.fbAsyncInit = function() {
 FB.init({
 appId : <?=YOUR_APP_ID?>,
 status : true,
 cookie : true,
 xfbml : true,
 oauth : true,
 });



FB.Event.subscribe('auth.login', function(response) {
 // ------------------------------------------------------
 // This is the callback if everything is ok
 window.location.reload();
 });
 };

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

And the logout. 并注销。

function logout_action()
    {
        $srv_nms=BASE;
        $srv_nms=str_replace("http://","",$srv_nms);
        $srv_nms=str_replace("https://","",$srv_nms);
        $srv_nms=str_replace("www.","",$srv_nms);


        $srv_pats=$srv_nms;

        $srv_nms_arr=explode("/",$srv_nms);
        $srv_nms=$srv_nms_arr[0];


        $srv_pats=str_replace($srv_nms."/","",$srv_pats);


        setcookie(COOKIE_LOGINID,"",0,"/".$srv_pats,$srv_nms);
        setcookie(COOKIE_USERNAME,"",0,"/".$srv_pats,$srv_nms);
        setcookie(COOKIE_PASSWORD,"",0,"/".$srv_pats,$srv_nms);

    session_start(); 
session_destroy();

        header("Location: ".$this->make_url("user/login/l"));
        die;
    }

I think I would use a cookie. 我想我会使用Cookie。 Upon logout, set a cookie telling you that the have requested logout. 注销后,设置一个cookie告诉您已请求注销。 Then on the main page, before grabbing data from facebook API, check for the cookie. 然后在主页上,在从facebook API获取数据之前,检查cookie。 Obviously you would have to overwrite or expire the cookie upon login...but this should solve it for you. 显然,您必须在登录时覆盖cookie或使其失效……但这应该可以为您解决。

in logout action you are logging out by session_destroy which will clear session in your server only, not in api. 在注销操作中,您要通过session_destroy注销,这将仅清除服务器中的会话,而不清除api中的会话。

so you need make $facebook->api logout request to logout from facebook completly. 因此,您需要发出$ facebook-> api注销请求才能从Facebook完全注销。 NOTE: refer api documentation for logout request. 注意:有关注销请求,请参阅api文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM