Facebook application saves previous user data

I have a problem with facebook iframe application. My problem is that if the user enters the application, then exits the application and another (different) user log is registered, $ facebook-> getUser () returns the identifier of the previous user.

I tried to send the user to the login URL every time, but this is the same until the page is refreshed once (the first login to the application will take the previous user session fb, and then it’s normal).

The only thing I could find is that this is due to persistent data in the $ facebook-> getUser () method ...

Perhaps someone can help shed light on this question, because after many times I could not find a solution ... Thank you!

+4
source share
1 answer

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

$ facebook-> getUser () method first check its private variable if the user is already set or not here, this 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 call the first time variable user , it is null

now it calls 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 getSignedRequestCookieName() return

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

now the getSignedRequest() function first checks if the signed request is installed or not, if not installed, it receives the signed request from the cookie

therefore, if, finally, if you do not want to receive the previous user ID, simply delete the cookie named ''fbsr_'+YourApplicationID'

0
source

Source: https://habr.com/ru/post/1381301/


All Articles