Be a Supporter!

Php Session Variables To As 3

  • 222 Views
  • 4 Replies
New Topic Respond to this Topic
TheNavigat
TheNavigat
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 04
Programmer
Php Session Variables To As 3 2013-03-20 17:03:11 Reply

Hello :)

The game I'm working on is linked with "accounts" that are saved in databases. What I want to do is to get the username into the game. I searched for some time and I got this, http://stackoverflow.com/questions/11608273/how-to-get-sessi on-variable-in-as3 , but the whole problem is to make it secured enough. Although I don't know how it really works, but I don't want the user to be able edit the code using Chrome for example, change data and play with everything.

Another solution was to call a PHP script, but the problem with it is that multiple people will be playing the game. Saving data to files is a bad idea regarding that, and session variables won't be available since the call will probably be local, not the same way the user browses it. Can someone tell me if it will actually work? Because maybe it does :/

Any help is appreciated, of course. Thanks.


Nav.. I'm the Nav!

Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to Php Session Variables To As 3 2013-03-21 15:14:20 Reply

To begin with you should make a PHP script to echo out the data you need in a similar fashion (forgive me, I don't really have experience in PHP):

echo "username=" + $sessionUser; // Where sessionUser is the username of the current session

From here, you can make a request to that page:

var request:URLRequest = new URLRequest("myPhpPage.php");
var loader:URLLoader = new URLLoader();

loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(request);
loader.addEventListener(Event.COMPLETE, loadedRequest);

Your loadedRequest method would look something like this:

private var playerName:String;

private function loadedRequest(e:Event):void
{
    playerName = e.currentTarget.data.username;
}

"playerName" should now be equal to what "username" would be upon calling the PHP page. Your PHP page can also include loads of information about the user in the current session, which every game could then utilise.

TheNavigat
TheNavigat
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to Php Session Variables To As 3 2013-03-22 06:06:40 Reply

The problem is that the echoed data must be according to the session and cookies saved for each user. Accessing it through Flash game would be technically different from that when the user actually opens a new tab and browses the same link...


Nav.. I'm the Nav!

Mattster
Mattster
  • Member since: Nov. 21, 2007
  • Offline.
Forum Stats
Member
Level 20
Game Developer
Response to Php Session Variables To As 3 2013-03-22 07:52:52 Reply

At 3/22/13 06:06 AM, TheNavigat wrote: The problem is that the echoed data must be according to the session and cookies saved for each user. Accessing it through Flash game would be technically different from that when the user actually opens a new tab and browses the same link...

Try passing flash the session_id, then pass that to the php page in any of your calls.

TheNavigat
TheNavigat
  • Member since: Mar. 2, 2013
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to Php Session Variables To As 3 2013-03-22 17:14:21 Reply

At 3/22/13 07:52 AM, Mattster wrote: Try passing flash the session_id, then pass that to the php page in any of your calls.

How can I do that? :|


Nav.. I'm the Nav!