0
votes

My problem is the following. I have a website http://de.gamercharts.com/

You can connect with facebook(if you don't have an account,an account will be created). After this ,if you logout from the site ,you are logged out from facebook too. Everything is ok so far. The problem is that if I am logged out of the site (let's call the site GC) and logged out of facebook ,when I click "connect with facebook" on the site,I get logged in on the site,instead of being prompted to the facebook login screen. When I print the user ,I see that even though I am logged out of facebook,I still have the user id. Why does this happen,and how can I fix it ? Thanx a lot to anyone who takes the time to answer. For the record I am using Zend ,although I don't think it's relevant. I did not implement the facebook login myself,I am continuing the work of someone else.

2
This is a well known problem. Can you paste your facebook logout script? - curious_coder
I don't handle the facebook logout myself.I do a redirect to facebook like so:facebook.com/…. You can pass a url to this function,url which is our own logout function,which deletes the GC session. - Alin Niculescu
What I don't understand is why I still see my FB user id when I am logged out of facebook.I just want to make my question more obvious. - Alin Niculescu
are you using facebook php sdk? - curious_coder

2 Answers

1
votes

The problem is caused due to existence of Facebook Session Variables in your domain/site, even after logging out from facebook and your site. When someone logs out from your site, one should take care to destroy all the sessions[even facebook sessions]. For destroying facebook sessions in your domain/site, you can make use of the function destroySession(); [provided in the facebook php sdk] in your logout script.

 $config = array();
 $config['appId'] = 'YOUR_APP_ID';
 $config['secret'] = 'YOUR_APP_SECRET';
 $facebook = new Facebook($config);
 $logout = $this->facebook->getLogoutUrl(array('next'=>'url to be redirected after logout'));
 $facebook->destroySession(); // To destroy facebook Sessions
 $session_destroy(); //To destroy sessions of your site
 header("Location:$logout");

P.S Don't forget to include or call session_start() in the script

0
votes

If you use facebook sdk, then you need use exception try-catch for checking if user is still logged in:

 1$facebook = new Facebook(array(
 2  'appId'  => you id,
 3  'secret' => you secret,
 4));
 5
 6// See if there is a user from a cookie
 7$user = $facebook->getUser();
 8
 9if ($user) {
10  try {
11    // Proceed knowing you have a logged in user who's authenticated.
12    $user_profile = $facebook->api('/me');
13  } catch (FacebookApiException $e) {
14    error_log($e);
15    $user = null;
16  }
17}

And after that you can get correct user id and other information from Facebook


Every time you need to request me-page. And if this page throw an error, then delete facebook user's data. User's id, and other facebook data stored in the cookies; when you logged out in the Facebook site, cookies for you site continue to be kept; your php-code will read this cookies:

1$user = $facebook->getUser();

and return user id. With this code:

1$user_profile = $facebook->api('/me');

you check if this cookies is actuall, and if it isn't, you change it:

1$user = null;

All the matter in cookies