I am trying to pass access token as a php session
Something weird is happening and I can't understand why.
fbconfig.fb
<?php
session_start();
// added in v4.0.0
require_once 'autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// init app with app id and secret
FacebookSession::setDefaultApplication( 'xxxxxxxx','xxxxxxxxx' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('http://www.something.net/triviapp/1353/fbconfig.php' );
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
// When Facebook returns an error
} catch( Exception $ex ) {
// When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
// graph api request for user data
$request = new FacebookRequest( $session, 'GET', '/me' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
$firstname = $graphObject->getProperty('first_name');
$lastname = $graphObject->getProperty('last_name');
$femail = $graphObject->getProperty('email'); // To Get Facebook email ID
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $fbid;
$_SESSION['FULLNAME'] = $fbfullname;
$_SESSION['EMAIL'] = $femail;
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
$accessToken = $session->getAccessToken();
$_SESSION['accesstoken'] = $accessToken;
//echo $_SESSION['accesstoken'];
/* ---- header location after session ----*/
header("Location: index.php");
} else {
$loginUrl = $helper->getLoginUrl();
header("Location: ".$loginUrl);
}
?>
so far so good. I get connected and I get the access token and send user to index.php
index.php is where facebook connects starts and I check to see if I have a facebook session. if I don't I send user to above file fbconfig.php, eitherwise I send user to the html5 app (a file named mobile.php)
anyway when I try to access $_SESSION['accesstoken'] in mobile.php the code breaks. The code just end itself where I try to output that session and I can't understand why.