设置使用Flash的ActionScript PHP会话变量 [英] Setting PHP session variables using Flash Actionscript

查看:215
本文介绍了设置使用Flash的ActionScript PHP会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从我的Flash应用程序称为一个简单的PHP上传脚本。我相信它使调用,因为它实际上将文件上载!

I have a simple PHP upload script that is called from my Flash App. I am sure it makes the call because it actually uploads the file!

session_start();

$default_path = 'files/';

$target_path = ($_POST['dir']) ? $_POST['dir'] : $default_path;

if(!file_exists($target_path)) mkdir($target_path, 0777, true);

$destination = $target_path . basename( $_FILES[ 'Filedata' ][ 'name' ] );

$file_name =  rand(1,9999).$_FILES[ 'Filedata' ][ 'name' ];

if(move_uploaded_file($_FILES[ 'Filedata' ][ 'tmp_name' ], $destination)){

$_SESSION['path'] = 'flashuploader_online/upload/'.$destination;

}

不过,我尝试在另一个脚本中使用会话变量路径,但它给了我一个空值!是的,我已经确定要使用session_start。

However, I try to use the session variable "path" in another script but it gives me an empty value! Yes, I have made sure to use session_start.

我缺少的东西?

至少现在我知道是什么问题!但我不知道如何解决它,没有它变得杂乱通过跨会话变量。任何想法?

At least now I know what the problem is! But I am not sure how to solve it without it getting messy to pass across session variables. Any ideas?

推荐答案

您将必须通过将它作为一个变量来坚持在所有请求SESSION_ID。我保证它不会太乱了!有一对夫妇的改变,你需要对显示的闪光灯以及脚本它张贴到页面。此外,还需要作出轻微变化到Flash应用程序本身,以便它可以包括会话ID时,它文件上载到服务器。

You are going to have to persist the session_id across all requests by passing it as a variable. I promise it won't get too messy! There are a couple changes you will need to make to the page that displays the flash as well as the script it posts to. You will also need to make a slight change to the Flash application itself, so that it can include the session ID when it uploads the file to the server.

首先,你会希望通过Flash变量,包括它提供的闪存与会话ID。你会需要一台显示Flash是pprocessed用PHP $ P $的页面,否则将无法坚持一个会话。请确保您调用session_start()在输出的Flash页面。你最终的东西是这样的:

First, you will want to provide flash with the session ID by including it with FlashVars. You're going to need the page that is displaying the flash to be preprocessed with PHP, or it will not be possible to persist a session. Make sure you call session_start() in the page that outputs the Flash. You'll end up with something like this:

<object classid="clsid:(blah)" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="800" height="800" id="ZoomifyHotspotViewer">
  <param name="flashvars" value="phpsessionid=<? print session_id(); ?>">
  <param name="src" value="YourSWF.swf">
  <embed flashvars="phpsessionid=<? print session_id(); ?>" src="YourSWF.swf" pluginspage="http://www.adobe.com/go/getflashplayer" type="application/x-shockwave-flash" width="800" height="800" name="YourSWF"></embed>
</object>

这部分,特别是需要添加,在参数和embed标签两种:

This part in particular is what needs to be added, in both the param and embed tags:

phpsessionid=<? print session_id(); ?>

然后,当你要求你的Flash应用程序,你现在可以访问的变量'phpsessionid会话ID。您需要包括在名为PHPSESSID POST变量中的值(全部大写) - 包括它不过你包括你的其他变量,如目录变量,你使用

Then, in your Flash app when you make the request, you will now have access to the session id in the variable 'phpsessionid'. You need to include the value in the POST variable named PHPSESSID (all caps) - include it however you are including your other variables such as the 'dir' variable you make use of.

包括变量将确保当你调用session_start()的下一个页面上,该会议将被恢复,而不是开始一个新的会话。有几个配置的情况下,这不会自动发生。如果原来是你的情况下(即会话ID依然是下一个页面上不同的),你需要做的是在上载页面如下:

Including that variable will ensure that when you call session_start() on the next page, the session will be restored instead of a new session being started. There are a couple configuration cases where this doesn't happen automatically. If that turns out to be the case for you (i.e. the session id is still different on the next page), you need to do the following in the page that processes the upload:

session_id($_POST['PHPSESSID']);
session_start();

这将手动强制PHP与指定的ID更新保存的会话。这甚至不应该是一个问题,你必须处理,但如果它是你必须做的用户继续到下一个页面上类似的东西为好,或添加一般情况下所有页面:

This will manually force PHP to renew the saved session with the specified ID. This shouldn't even be an issue you have to deal with, but if it is you may have to do something similar on the next page the user continues to as well, or add a general case to all pages:

if (isset($_REQUEST['PHPSESSID'])) {
  session_id($_REQUEST['PHPSESSID']);
}
session_start();

要确保,如果你最终需要调用的session_id()用这种方式作为二传手,你这样做的之前调用在session_start()。

Be sure that if you do end up needing to call session_id() in this way as a setter, that you do so before calling session_start().

这篇关于设置使用Flash的ActionScript PHP会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆