Take the 2-minute tour ×

I'm having some trouble passing a simple variable to Flash from a php file that connects to facebook. Here's what I do:

When the user comes in to my game, he has the option to login using facebook. If he chooses to do so, I call a php file, that takes him to facebook, where he allows acess to the game and then facebook redirects him to the game. Once in the game again, I call the same file with a LoadVars, in order to get the user info from facebook. Since the user is already connected to facebook, the variables should be passed to Flash normally, but they simply don't. If I execute the PHP only, I can see the variable normally, but it simply won't go to Flash.

I did a workaround by redirecting the user to another php file, after allowing access on facebook. This php file would then redirect the user again to the flash game index, and then the variable would be passed normally! The thing is, since I'm redirecting the user to a different url sometimes I get a redirect error... and I didn't wan't to use this method.

Any ideas?

Here's my php code:


require_once '../facebook.php'; // Require the Facebook PHP SDK

$config = array();
$config[appId] = 'xxxx';
$config[secret] = 'xxxx';
$config[fileUpload] = false;
$facebook = new Facebook ($config);

$user = $facebook->getUser();

if ($user) { // Succesfully got the user id. User is logged in to facebook
    $userProfile = $facebook->api('/me'); // Get the basic user info from his profile

    $toGame = "";
    $toGame .= $userProfile['first_name']."#";
    $toGame .= $userProfile['middle_name']."#";
    $toGame .= $userProfile['last_name']."#";
    $toGame .= $userProfile['birthday']."#";
    $toGame .= $userProfile['email']."#";
    $toGame .= $userProfile['gender'];

    echo $toGame;
else { // Failed to get the user's facebook id. Tell him to log on facebook
    $params = array ();
    $params[scope] = 'publish_stream, user_birthday, email';
    //$params[redirect_uri] = 'xxx';
    $params[redirect_uri] = 'xxx';

    echo "needLogin#".$loginUrl; // Tell Flash to redirect the user to the facebook connect page

share|improve this question
Can you show the Flash code bit? –  Lukasz 'Severiaan' Grela Feb 28 '13 at 13:32
Sorry, I don't have access to it... but I can confirm that the code is ok. It seems to be a Flash bug or something, because Flash CAN get the variable correctly, but only if I redirect the user to another php and then back to the index with the game swf... or if I refresh the browser and use the Login with Facebook button again. Then, since I'm already logged in, Flash get the variable normally. It's weird... it's like Flash can't get the variable on the first attempt right after the facebook redirect. –  DanielFox Feb 28 '13 at 13:39

Your Answer



Browse other questions tagged or ask your own question.