Session Variables and AMFPHP – taterboy
September 3rd, 2008 | Filed under: AMFPHP, Flash, Flex, Tips
In normal uses PHP and other server/scripting languages are able to store variables for later usage. Due to the fact that the these pages are not actually living in a browser, remoting is one of the exceptions where variables do not live between calls. We have to plan out our Flash to PHP conversations as if PHP has very short term memory and include all the needed data to complete every transaction. For instance, if you have to store information in a database using a userID, even though you have just recieved that userID from php, your next php call will have to include the userID because PHP just can not remember.
Here is a demo of using PHP session variables to temporarily store and read data. Even though normal variables vanish, session information is live and well.
This demo was built a while ago in AS2, but all the session code only effects the PHP side so the results should work with AS3 as well. There are some nice AS3 AMFPHP remoting tutorials already on the web. Here are a few of the many possible links: GotoAndLearn, Caleb.org
Starting php sessions are really simple.
//place this at the top of the page session_start(); //use this syntax to add data to a session variable. $_SESSION[$name] = $value; //pulling data is just as straight forward. return $_SESSION[$name]; |
To use the demo, type an interesting string into one of the input boxes then press “TELL”. To recall the string from the session variable, press “ASK”. You will see status information appear in the output areas.
Demo.
source here
|
RSS feed for comments on this post. TrackBack URL
Thanks for the tutorial…
Comment by handoyo — July 18, 2009 @ 8:53 pm