Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7919385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:50:49+00:00 2026-06-03T15:50:49+00:00

The question is the same as title. I’m using the latest php-sdk (v3.1.1) to

  • 0

The question is the same as title. I’m using the latest php-sdk (v3.1.1) to operate server-side authentication flow.

I have 2 tabs in Chrome, one is my Facebook page and the other is php test page. These 2 problems happen many times:

  • $facebook->getUser() still returns 0 even when I logged in.
  • $facebook->getUser() still returns an ID even when I logged out.

I have to do a work-around of this: try initiating a graph API request with provided access_token, and check if $response->error->type == "OAuthException" to ensure there’s an active session or not.

Is there any way to use $facebook->getUser() “stably”? I’ve searched a lot through SO but not found best answer for php-sdk 3.1.1 yet.

Highly appreciate any helps. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:50:51+00:00Added an answer on June 3, 2026 at 3:50 pm
    1. Login.
      As per documentation example of FB SDK, getUser() returns userId even when you’re logged out, but have cookies associated with FB account.
      To detect is user logged in you should use

      $user = $facebook->getUser();
      //Check Access token
      if ($user) {
           try {
              $user_profile = $facebook->api('/me');
           } catch (FacebookApiException $e) {
              $user = null;
           }
      } 
      if ($user) { 
          //logged-in
      } else {
          //not logged-in
      }
      

      To login in your app make user logs in in your app, not on neighbouring tab, by following this url (make sure that you’re passing the scope based on intended actions performed by your app):

      $loginUrl = $facebook->getLoginUrl(
          'scope' => ...
      );
      
    2. Logout. Seems that your PHP server is storing some values of access tokens per session, so even when you’re logged out in your browser, your server still have these tokens valid. Actually, I don’t know, is it bug or feature, but they’re not destroyed by Facebook after user logout.

      To destroy these tokens I’m using these:

      $facebook->destroySession();
      

      I’m calling it every time when user logs-out by $facebook->getLogoutUrl();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have question with this same title here but now as I'll present in
My question is same as the title. I have not done Test driven development
Again same question title but requirement is somewhat different. We have implemented push notification
I have the same problem like this question: Custom title bar in PreferenceActivity? After
There is a question here in stackoverflow with the same title but that is
Same question for Windows Server 2003. Do I need to direct people to install
I have the same question problem as described here How to purge a cached
I have the same question as #1895500 , but with PostgreSQL not MySQL. How
I have the same question for Maven that someone had about Ant ( How
I know that question with same title has been asked almost 6 month ago.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.