homelessDevOps
homelessDevOps

Reputation: 20726

Facebook Application with PHP running losing session

Iam trying to build an Facebook Application based on PHP. The Application is running under php on my own Webhost inside an Canvas as iFrame.

I have included the newest Client Library for PHP from Facebook: facebook-php-sdk-94fcb13

To Authorize the user inside my application iam trying to use Facebook Connect, like the example shipped with the Client. Everything works fine the 1st Login, but when i hit the F5 Key to reload the page, the session is lost and i have to login again. When i call my application outside of the Facebook Canvas everything is fine.

Iam not sure, but i think my Browser (Chrome/FireFox - Ubuntu) is not allowing to store an cookie inside an iFrame.

Does someone knows an solution for this Problem? Here are some Parts of the Sourcecode:

$facebook = new Facebook(array(
    'appId'  => 'x',
    'secret' => 'x',
    'cookie' => 'true',
));

$session = $facebook->getSession();
$facebook->setSession($session);


$me = null;
// Session based API call.
if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}

// login or logout url will be needed depending on current user state.
if ($me) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}

Upvotes: 1

Views: 4184

Answers (2)

karthi
karthi

Reputation: 11

php passes the session id via a cookie value , if its not able to send it , sends via get parameter like *.php?phpsessid......

It will get lost if u use header() redirection , solution append .SID in url,

like

header("blah blah".SID);

Hope it helps you..

Upvotes: 1

homelessDevOps
homelessDevOps

Reputation: 20726

Solved :-)

I have missed to setup the basedomain in configuration.

On the "Conntect" Tab you have to set the Basedomain to your host.

Example: Application is running under http://myapp.com/facebook/html than set the basedomain to myapp.com

Now the cookie is stored correctly.

Upvotes: 1

Related Questions