A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Reading PHP Session Variable

  1. #1
    Member
    Join Date
    Oct 2006
    Posts
    45

    Reading PHP Session Variable

    Hey all,
    I'm just trying to do a scene change in flash depending on the existence of a PHP session variable. How does Actionscript read PHP session vars?

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    You'll need to have a PHP script grabbing all the information you want from the Session. This script outputs the information as a variable sessionInfo for example.
    Like this, Flash can load that variable from the PHP script using the LoadVars Class.

    code:

    // set a LaodVars Object to load and preload the data
    var my_lv:LoadVars = new LoadVars();
    // when the data finishes loading
    my_lv.onLoad = function(ok:Boolean)
    {
    if (ok)
    {
    trace(this.sessionInfo);
    }
    else
    {
    trace("error");
    }
    }
    my_lv.load("script.php");

    Last edited by nunomira; 04-17-2007 at 09:12 PM.

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    4
    Hi there I am having a similar problem:

    When trying to access my flashdata.php file from within my Flash Movie, my Flash Movie receives a different session ID than the logged in user, and so my session variables do not contain any data.

    How can I pass the session ID of the logged in user to the Flash Movie so that it can obtain the relevant session variables?

    Thank you!

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    If the user has already logged in outside Flash, a session variable already exists and you can pass it to Flash via FlashVars. You can then use it, if needed, by appending it to the url.

    If the user logs in from Flash, I can't see how this is possible... That would mean that a new session variable is created each time you make a new call, which doesn't make much sense (although such thing exists, as a means to prevent session hijacking).

  5. #5
    Junior Member
    Join Date
    Jan 2010
    Posts
    4
    Thanks for your quick reply.

    The users do not log in through flash, hence the difference in session id's.

    How would I go about using FlashVars to send the session ID to Flash? (I am somewhat of a newb at ActionScript).

    Thank you.

  6. #6
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    In the documentation for SWFObject, there's an example under "How do you use JavaScript Objects to define your flashvars, params and object's attributes?".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center