简体   繁体   English

如何在Flash AS3和PHP之间共享会话?

[英]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). Flash的登录页面,用户会将用户名和密码发送到php文件(login.php)。 IF login success, it will return echo "success" and create session there. 如果登录成功,它将返回echo“ success”并在那里创建会话。 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. 然后在瞬间,当我单击购物按钮时,它将转到www.domain.com/shopping/index.php,该index.php将进行一次会话以检查访问者是否已登录。 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? 在login.php中创建的会话变量在哪里?

How to share session variables between flash and php?? 如何在Flash和PHP之间共享会话变量?

I got it. 我知道了。

You can do an asynchronous call from Flash to PHP to get the session. 您可以从Flash到PHP进行异步调用以获取会话。 Example: 例:

In your Actionscript.as: 在您的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 在您的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. 您也可以执行JSON语法(如果您是受虐狂,请执行XML)来获取更复杂的数据结构。 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 . 至于在PHP和ActionScript之间共享变量,最好的办法是设置AMF远程服务器 You can use a Remoting Framework to send requests to the server and get native ActionScript objects as the response. 您可以使用Remoting Framework将请求发送到服务器,并获取本机ActionScript对象作为响应。 PHP should be able to keep track of the users session and respond to AMF requests with session relevant data. PHP应该能够跟踪用户会话并使用会话相关数据响应AMF请求。

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. 当您向PHP发送请求时,Flash应该将当前会话ID传递给它,不幸的是Flash并没有这样做,因此需要将会话ID作为URL变量传递给php页面,以便您的php获得该会话。 for more info check this. 有关更多信息,请检查此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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