Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6780933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:33:52+00:00 2026-05-26T16:33:52+00:00

I’m having issues with loading the user’s information into Flash from a PHP script.

  • 0

I’m having issues with loading the user’s information into Flash from a PHP script.

EDIT: index.php is called by Facebook to Authenticate. Flash then calls database.php to connect to the database and store/recall the players information and progress. Database.php then encodes the array and echos it out to Flash where it is parsed.

This was working up until last weekend.

index.php

<?php
$app_id = "my_id";
$app_secret = "my_secret";
$my_url = "http://apps.facebook.com/my_app";

session_start();
$code = $_REQUEST["code"];

if(empty($code)) 
{
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
 $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
   . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
   . $_SESSION['state'];

 echo("<script> top.location.href='" . $dialog_url . "'</script>");
 exit;
}

if($_REQUEST['state'] == $_SESSION['state']) {
 $token_url = "https://graph.facebook.com/oauth/access_token?"
   . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
   . "&client_secret=" . $app_secret . "&code=" . $code;

 $response = file_get_contents($token_url);
 $params = null;
 parse_str($response, $params);

 $graph_url = "https://graph.facebook.com/me?access_token=" 
   . $params['access_token'];

 $user = json_decode(file_get_contents($graph_url));
 //echo("Hello " . $user->name);
 include_once 'game.php';
}
else 
{
    echo("The state does not match. Try opening the app from the homepage.");
    include_once 'game.php';
}
?>

database.php

<?php
require 'src/facebook.php';

$facebook = new Facebook(array(
 'appId'  => 'my_id',
 'secret' => 'my_secret',
));

// Get User ID
try 
    {
    $user = $facebook->getUser();

    if ($user) 
        {
            $user_profile = $facebook->api('/me');

            //$friends = $facebook->api('/me/friends');
            //print_r($friends);
            mysql_connect("localhost", "DB_USER", "DB_PASS") or die("Could not connect");
        mysql_select_db("stus_zombies") or die("Could not select database");

        $query = mysql_query("SELECT * FROM users WHERE facebook_id = " . $user_profile[id]);  
        $result = mysql_fetch_array($query);

        if(empty($result))
        { 
            $addInfo = mysql_query("INSERT INTO users (first_name, last_name, facebook_id) 
            VALUES ('{$user_profile['first_name']}','{$user_profile['last_name']}','{$user_profile['id']}')");  
                $addInfo = mysql_query("SELECT * FROM users WHERE id = " . mysql_insert_id());  

            $query = mysql_query("INSERT INTO players (facebook_id, coins, health, stamina, xp)
            VALUES ('{$user_profile['id']}','0','25','25','0')");
        }

        $checkProgress = mysql_query("SELECT * FROM players WHERE facebook_id = " . $user_profile[id]);
        $playerCheck = mysql_fetch_array($checkProgress);

        $playerInfo = array(
        first_name => $user_profile[first_name],
            last_name => $user_profile[last_name],
            facebook_id => $user_profile[id], 
            //facebook_access_token => $_SESSION[fb_165114483572553_access_token],
            coins => $playerCheck[coins],
        health => $playerCheck[health],
        stamina => $playerCheck[stamina],
        xp => $playerCheck[xp],); 
        echo json_encode($playerInfo);
        } 

    else
    {
        echo ("No User");
    }
}

catch (FacebookApiException $e) 
{
    error_log($e);
        $user = null;
    }
?>

I changed to a different authentication method, and that worked for a couple hours before it stopped.

The second index.php I tried:

 <?php

 $app_id = "165114483572553";

 $canvas_page = "https://apps.facebook.com/MY_APP";

 $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
        . $app_id . "&redirect_uri=" . urlencode($canvas_page);

 $signed_request = $_REQUEST["signed_request"];

 list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

 $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

 if (empty($data["user_id"])) {
        echo("<script> top.location.href='" . $auth_url . "'</script>");
 } else {
 include_once 'game.php';
 } 
 ?>

AS3 Class database.as

package  
{
import flash.events.IOErrorEvent;
import com.adobe.webapis.URLLoaderBase;
import flash.events.Event;
import flash.net.*;
import com.adobe.serialization.json.JSON;
import org.flashdevelop.utils.FlashConnect;
import HUD.UI;

public class Database
{
    // Page Loader
    private static var loader:URLLoader;
    private static var dataloader:URLLoader;

    // User Info
    private static var playerData:Object;

    //TEST
    // Player Info
    private static var playerLoader:URLLoader = new URLLoader();
    private static var playerRequest:URLRequest = new URLRequest;
    playerRequest.url = "http://MYURL/database.php";

    public function Database() 
    {

    }

    public function getPlayer():void
    {
        playerLoader.load(playerRequest);
        playerLoader.addEventListener(Event.COMPLETE, decodeJSONPlayer);
        playerLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
    }
    // Decode JSON (Player Coins, ID, Stamina, Health, XP)
    private function decodeJSONPlayer(e:Event):void
    {
        playerLoader = URLLoader(e.target);
        playerData = JSON.decode(playerLoader.data);
        loadPlayerInfo(playerData);
        // Display stats info
        UI.updateHealth();
        UI.updateMoney();
        UI.updateXP();
        UI.updateStamina();
    }

    // Load database info into player's data
    private function loadPlayerInfo(playerData:Object):void
    {
        Player.first_name = playerData.first_name;
        Player.last_name = playerData.last_name;
        Player.facebook_id = playerData.facebook_id;
        Player.facebook_access_token = playerData.facebook_access_token;
        Player.health = playerData.health;
        Player.stamina = playerData.stamina;
        Player.money = playerData.coins;
        Player.xp = playerData.xp;
        trace(playerData.first_name);
        // Display Facebook info
        UI.txtFacebookInfo.text = playerData.first_name +" " + playerData.last_name +" " + playerData.facebook_id;
    }

    // Save all Progress
    public static function setAll(_money:int, _health:int, _stamina:int, _xp:int):void
    {
        var vars:URLVariables = new URLVariables();
        vars.money = _money;
        vars.health = _health;
        vars.stamina = _stamina;
        vars.xp = _xp;

        var request:URLRequest = new URLRequest("http://MYURL/saveplayer.php");
        request.method = URLRequestMethod.POST;
        request.data = vars;

        if (loader != null)
        {
            loader.removeEventListener(Event.COMPLETE, pageLoaded);
        }

        loader = new URLLoader();
        loader.dataFormat = URLLoaderDataFormat.TEXT;
        loader.load(request);
        loader.addEventListener(Event.COMPLETE, pageLoaded);
    }

    private static function pageLoaded(e:Event):void
    {
        trace("PAGE LOADED\n============================");
        FlashConnect.trace(loader.data);
        trace("============================");
    }

    private static function completeHandler(event:Event):void
    {
        var loader:URLLoader = URLLoader(event.target);
        FlashConnect.trace(loader.data.dayNames);
    }

    // Server info not received
    private function onIOError(e:Event):void
    {
        trace ("Error loading URL");
    }
}

}

Changing it back to the original code worked till the next day before it stopped working.

I managed to get it working with a temporary fix by including the database script in with the index script and then calling it from Flash.

That just stopped working. Obviously this is driving me insane. Including database.php in index.php even now will trace echo out the JSON information correctly, but it isn’t loaded into the game.

On the Flash side, I had it hooked up to a button so I could call it and see the return and it seemed to be working fine. I am never getting errors returned when it doesn’t load the player’s information which makes troubleshooting this trial and error and research.

Any help would be greatly appreciated. I have spent way too much of my time adapting scripts and researching at this point when there is someone out there that knows what is going on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:33:53+00:00Added an answer on May 26, 2026 at 4:33 pm

    This was a domain issue with Facebook sometimes calling my domain with ssl which was different than the unsecured domain. Solved by forcing it and my app to call the secure domain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.