PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 15, 2022

[FIXED] facebook application keeps previous user details

 January 15, 2022     facebook, facebook-php-sdk, session     No comments   

Issue

I'm having a problem with a facebook Iframe application. My problem is that if a user logs in to the app, then logs out of the application and another (different) user logs in, the $facebook->getUser() returns the id of the previous user.

I tried to send the user to the login url each time, but it still happens untill the page is refreshed once (first login to app takes the previous user fb session, then its ok).

The only lead I was able to find was that this happens due to the persistent data in the $facebook->getUser() method...

Maybe someone can help shed some light on this matter, as after a lot of times I couldn't find a solution... Thanks!


Solution

You are using facebook PHP SDK right. In facebook php sdk when you call the

$facebook->getUser() method it first check it it's private variable if user already set or not here is the method

   * Get the UID of the connected user, or 0
   * if the Facebook user is not connected.
   *
   * @return string the UID if available.
   */
  public function getUser() {
    if ($this->user !== null) {
      // we've already determined this and cached the value.
      return $this->user;
    }
    return $this->user = $this->getUserFromAvailableData();
  }

so if you are call the first time of-course user variable is null

so now it call getUserFromAvailableData(); method

   /** * Retrieve the signed request, either from a request parameter or,
   * if not present, from a cookie.
   *
   * @return string the signed request, if available, or null otherwise.
   */
  public function getSignedRequest() {
    if (!$this->signedRequest) {
      if (isset($_REQUEST['signed_request'])) {
        $this->signedRequest = $this->parseSignedRequest(
          $_REQUEST['signed_request']);
      } else if (isset($_COOKIE[$this->getSignedRequestCookieName()])) {
        $this->signedRequest = $this->parseSignedRequest(
          $_COOKIE[$this->getSignedRequestCookieName()]);
      }
    }
    return $this->signedRequest;
  }

and the getSignedRequestCookieName() return

protected function getSignedRequestCookieName() {
    return 'fbsr_'.$this->getAppId();
   }

so now getSignedRequest() function first check whether signed request is set or not if not set it get signed request from Cookie

so if finally if you not want to get previous userid just delete cookie named ''fbsr_'+YourApplicationID'



Answered By - Anant Dabhi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing