简体   繁体   中英

How to share session between flash AS3 and PHP?

Login page in flash, user will send username and password to a php file(login.php). IF login success, it will return echo "success" and create session there. Then in flash, when i click shopping button, it will go to www.domain.com/shopping/index.php, that index.php will do a session check whether the visitor has login. But it seems like, i need to login again before can enter to the page. Where are my sessions variables that created in login.php?

How to share session variables between flash and php??

I got it.

You can do an asynchronous call from Flash to PHP to get the session. Example:

In your Actionscript.as:

    public function session(continuation:Function)
    {
        var request:URLRequest = new URLRequest("backend.php");
        var loader:URLLoader = new URLLoader();
        loader.addEventListener(Event.COMPLETE, continuation);
        loader.load(request);
    }

    public function function_that_uses_session()
    {
        this.session(function(evt:Event)
        {
            var omg_session = evt.target.data;
        }
    }

In your backend.php

 <?php echo $_SESSION['id']?>

You can also do JSON-syntax (or if you are a masochist, do XML) for more complex data structures. The rest lies in your imagination ;)

I wish I'm not too late yet in solving your answer

It sounds like its possibly not a flash problem? Can you test to see if the session data is being persisted between to two normal pages?

As far as sharing variables between PHP and ActionScript, The best thing to do would be to setup an AMF remoting server . You can use a Remoting Framework to send requests to the server and get native ActionScript objects as the response. PHP should be able to keep track of the users session and respond to AMF requests with session relevant data.

Hope this helps!

when you send request to a PHP, the flash should pass current session id with it, unfortunately flash is not doing the same so need to pass session id as URL variable to php page so that your php get that session. for more info check this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM