Ultimate Gear War
Join the alien war, prepare your gear and protect your base at all cost!
4.14 / 5.00 17,262 ViewsHello :)
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!
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.
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!
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.
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!