简体   繁体   English

$ facebook-> getUser()注销后返回一个用户ID

[英]$facebook->getUser() returns a userid after logout

How do I check if the user is really loggedin? 如何检查用户是否真正登录? $facebook->getUser() still returns an ID after logout. $facebook->getUser()在注销后仍返回ID。 Do I need to do something like $facebook->api('/me') just to check if the user is "really" logged in? 我是否需要执行类似$facebook->api('/me')来检查用户是否“真正”登录?

Well, FB PHP SDK in my opinion is quite tricky because it relies on a cookie sent from Facebook when you are logging into the Facebook. 好吧,我认为FB PHP SDK非常棘手,因为它依赖于您登录Facebook时从Facebook发送的cookie。 This cookie is not deleted whilst logging out. 注销时不会删除此cookie。 Because of that in below code the variable $uid could store a proper user facebook id: 因此,在下面的代码中,变量$ uid可以存储正确的用户facebook id:

$uid = $facebook->getUser();

So, as far as I know, call $facebook->api('/me'); 因此,据我所知,调用$facebook->api('/me'); will tell the truth whether the user is logged in or not. 会告诉用户用户是否已登录。

try {
   $facebook->api('/me');
   /* user is really logged into FB */
} catch (Exception $e) {
   /* user is not currently logged into the FB */
}

I use above code in my production application and it works well. 我在生产应用程序中使用了上面的代码,并且效果很好。

getLoginStatusUrl should do the trick. getLoginStatusUrl应该可以解决问题。 I think that if you ask for offline_perms than you have access to user_id and so on. 我认为,如果您要求offline_perms,则可以访问user_id等。 I don't know if you did, but most likely that should be the problem 我不知道你是否这样做,但很可能应该是问题所在

Have you tried the method detailed in the Facebook PHP SDK Documentation ? 您是否尝试过Facebook PHP SDK文档中详细介绍的方法?

$params = array(
  'ok_session' => 'https://www.myapp.com/',
  'no_user' => 'https://www.myapp.com/no_user',
  'no_session' => 'https://www.myapp.com/no_session',
);

$next_url = $facebook->getLoginStatusUrl($params);

Returns a URL based on the user's login status on Facebook. 根据用户在Facebook上的登录状态返回一个URL。 You can get a different URL depending on whether the user is logged in, not connected, or logged out of Facebook. 您可以根据用户是登录,未连接还是注销Facebook来获得其他URL。

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

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