Reputation: 87
<?php
require_once 'facebook.php';
$app_id = "";
$app_key = "";
$app_secret = "";
$canvas_url = "";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
'domain' => 'http://www.yeospace.com/2B10030/'
));
$session = $facebook->getSession();
if (!$session) {
try{
$url = $facebook->getLoginUrl(array(
'req_perms' => 'publish_stream, user_photos, read_stream, read_friendlists, offline_access, manage_pages'
));
echo "<script type='text/javascript'>top.location.href = '$url';</script>";
}
catch(FacebookApiException $e)
{//catch
echo "<br/>";
echo "Error:" . print_r($e, true);
}//catch
}//end if session user
else
{
$uid = $facebook->getUser();
$me = $facebook->api('/me');
//$updated = date("l, F j, Y", strtotime($me['updated_time']));
echo "<img src='https://graph.facebook.com/".$uid."/picture'/>". "<br />" ;
echo "Hello " . $me['name'] . "<br /><br /><br /><br />";
//echo "You last updated your profile on " . $updated . "<br />" ;
}//end else user
I have this application which is having logout problem. The code above is a config.php where every other page will include. "require_once 'config.php'" When i logout user A and login user B, then when i run the application again, the data in the application was still user A.
Is there anyway where i could force clear the data then load the new one? Even thought this config.php was always being load the user data was not cleared. Could you guys advice me on how i could clear this. I am still unfamiliar with facebook application. THank you!
Upvotes: 1
Views: 6932
Reputation: 1242
On facebook doc, they suggest to use:
Facebook::getLogoutUrl( $params=array() )
This method returns a URL that, when clicked by the user, will log them out of their Facebook session and then redirect them back to your application.
You should use following code:
$params = array( 'next' => 'https://www.myapp.com/after_logout' );
$facebook->getLogoutUrl($params);
Check facebook sdk ref. doc: https://developers.facebook.com/docs/reference/php/facebook-getLogoutUrl/
Upvotes: 0
Reputation: 6585
There are 2 things you are not doing in any of this code:
this is why you are preserving the state of the previous user even though you have switched users.
Upvotes: 1