jeudi 2 avril 2015

Why session is lost in Facebook SDK 4.4 after changing URL?

I have a basic php code made with Facebook SDK 4.4. After a Facebook user gives the app the right to receive public info I can display name, picture and so on. In order to do that first i get the session. If i click a link, even to the same page (index.php), i can not get the session anymore.


Why do you think the session is lost? If I hit F5 the session is back and I can receive users info, if i click again the link the session is lost.


Here is my code:



session_start();

$api_key = '...';
$api_secret = '...';

require_once 'autoload.php';

use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookCanvasLoginHelper;
use Facebook\FacebookSession;
use Facebook\FacebookRequestException;
use Facebook\SignedRequest;

FacebookSession::setDefaultApplication($api_key, $api_secret);

$helper = new FacebookCanvasLoginHelper();

try
{
$session = $helper->getSession();
}
catch(FacebookRequestException $ex)
{
// When Facebook returns an error
}
catch(\Exception $ex)
{
// When validation fails or other local issues
}

if($session)
{
print "session ok";
}
else
{
print "session not set";
}
?>
<br />
<a href="index.php">change url</a>


When i enter the app i see "session ok change url". If i click the link that redirects me to the same page i see "session not set change url". If i hit F5 i se again "session ok change url", and so on. What do I do wrong? Thanks


Aucun commentaire:

Enregistrer un commentaire