代码点火器 + TankAuth + Swfupload 无法获取记录器用户 ID

发布于 2024-10-06 16:14:17 字数 758 浏览 2 评论 0原文

我正在使用安装了 TankAuth 库的 Codeigniter,并尝试从 swfupload 上传到 index.php/requests/doUpload,但无法访问经过身份验证的页面。我在网上阅读了许多关于类似问题的帖子,并尝试设置 $config['sess_match_useragent'] = FALSE; ,但仍然没有区别。为了测试目的,我最终跳过了控制器中的登录检查。但现在我需要从控制器访问 TankAuth 库以获取当前登录的用户 ID。它是在我的应用程序中请求的并且无法跳过它,我确实需要将登录的用户 ID 传递给该 doUpload 模型。我有这样的设置控制器:

function doUploadFileFn() {
        if (!$this->tank_auth->is_logged_in()) {
            return;
        } else {
            $user_id = $this->tank_auth->get_user_id();
            $this->load->model('requests/doUploadFile');
            $this->doUploadFile->uploadData($user_id);
            }

    }

现在,它没有通过 is_logged_in() 检查,正如我从其他帖子中了解到的那样,CI 删除了会话,但我已经设置了配置不匹配用户代理,但仍然无法工作。

有什么解决办法吗?

I am using Codeigniter with the TankAuth library installed and trying to upload to index.php/requests/doUpload from swfupload but can't access the page as authenticated. I have read many posts around the net about similar problem and tried to set $config['sess_match_useragent'] = FALSE; but still no difference. I have ended up skipping the login check in my controller for testing purposes. But now I need to access tankAuth library from my controller to get the current logged in user ID. It is requested in my application and cannot skip it, I really need to pass the logged in user id to that doUpload model. I have setup controller like this:

function doUploadFileFn() {
        if (!$this->tank_auth->is_logged_in()) {
            return;
        } else {
            $user_id = $this->tank_auth->get_user_id();
            $this->load->model('requests/doUploadFile');
            $this->doUploadFile->uploadData($user_id);
            }

    }

Now, it does not pass the is_logged_in() check, as I learned from other posts, CI deletes the session but I have setup the config not to match the user agent but still not working.

Is there any solution to this out there ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心在旅行 2024-10-13 16:14:17

按照 CI 论坛中的教程,我能够实现您所要求的目标对于。
1) 将其放入 SWFUpload JS 配置中:

post_params: {"<?php echo $this->config->item('sess_cookie_name'); ?>" :"<?php echo $this->session->get_cookie_data(); ?>"},

2) 将 MY_Session.php 文件放入 application/libraries/ 文件夹中。

3)新库应该在视图加载时加载,如果没有(由于某种原因),则将库加载到控制器中。

PS:您需要设置:

$config['sess_match_useragent'] = FALSE;

否则将为用户代理创建一个新会话 Shockwave Flash

编辑: 好的,根据您的评论..您确实需要设置您的 < code>post_params 设置为您当前的会话,以便当 flash post 到您的控制器时可以将其发送,现在就您的情况而言,我能想到的最好的事情如下:
您的 externalUntouchableJsFile.js:

// JS scripts...  
...
var swfu = new SWFUpload({  
    ...
    ...
    post_params: GLOBAL_VAR,
    ...
});  
    ...  
// rest of your JS

在您的 PHP 视图中,在加载此 JS 文件之前,有类似以下内容:

<script>  
var GLOBAL_VAR = {};  
<?php if(session_is_there) { ?>
GLOBAL_VAR = {"<?php echo $this->config->item('sess_cookie_name'); ?>" :"<?php echo $this->session->get_cookie_data(); ?>"}
<?php } ?>  
</script>
<script type="text/javascript" src="<?php echo base_url() ?>path/to/js/externalUntouchableJsFile.js"></script>

编辑 2: 由于您使用的是外部 js 文件,您可能会忘记定义全局变量,因此请使用:

post_params: (typeof GLOBAL_VAR === 'undefined') ? {}:GLOBAL_VAR,

Following the tutorial in the CI forums I was able to achieve what you are asking for.
1) Put this in the SWFUpload JS config:

post_params: {"<?php echo $this->config->item('sess_cookie_name'); ?>" :"<?php echo $this->session->get_cookie_data(); ?>"},

2) And place the MY_Session.php file in your application/libraries/ folder.

3) The new library should be loaded the moment the view is loaded if not (for some reason) then load your library in the controller.

P.S: You need to set:

$config['sess_match_useragent'] = FALSE;

Otherwise a new session will be created for a useragent Shockwave Flash

EDIT: Okay, based on your comment..you really need to set your post_params setting to your current session so it can be sent when the flash post to your controller, now in your case the best thing I could think of is the below:
Your externalUntouchableJsFile.js:

// JS scripts...  
...
var swfu = new SWFUpload({  
    ...
    ...
    post_params: GLOBAL_VAR,
    ...
});  
    ...  
// rest of your JS

And in your PHP view and before loading this JS file have something like:

<script>  
var GLOBAL_VAR = {};  
<?php if(session_is_there) { ?>
GLOBAL_VAR = {"<?php echo $this->config->item('sess_cookie_name'); ?>" :"<?php echo $this->session->get_cookie_data(); ?>"}
<?php } ?>  
</script>
<script type="text/javascript" src="<?php echo base_url() ?>path/to/js/externalUntouchableJsFile.js"></script>

EDIT 2: Since you are using an external js file, you may forget to define the global variable so use:

post_params: (typeof GLOBAL_VAR === 'undefined') ? {}:GLOBAL_VAR,
喜爱纠缠 2024-10-13 16:14:17

值得一提的是,Flash 文件应该由与您的 CI 站点相同的域提供,否则将无法读取对方的 cookie。另请确保登录 cookie 路径设置为根路径。如果 SWFUpload 无法读取登录 cookie,它也无法发送它。

Flash 对会话 cookie 的访问受到限制,如 SWFUpload 论坛中所述。您是否可以设置自动登录以避免设置过期(在 config/tank_auth.php 中),从而使其成为会话 cookie?如果是这种情况,则 SWFUpload SWF 可能无法访问或发送自动登录 cookie 值,具体取决于计算机上 Flash 播放器的版本。使用 Firebug 等调试工具仔细检查 Cookie 过期值,看看是否属于这种情况。如果在您选中“记住”我框时上传有效,但在其他情况下无效,则表明存在会话 cookie 问题。

要强制 SWF 在文件上传时传递 TankAuth cookie 值,您可以首先重载 cookie 帮助程序 get_cookie 函数,以在 $_COOKIE 数组或 $_POST 数组中查找值。然后,使用 SWFUpload v2,您可以在上传时发送额外的 POST 值,并且这将是发送自动登录密钥的方式,然后您的控制器将能够获取 user_id。但在破解 Cookie 助手之前,请确保您的活动部件首先正常工作,如第一段中所述。

It bears mentioning that the Flash file should be served from the same domain as your CI site or one won't be able to read the other's cookies. Also make sure that the login cookie path is set to the root path. If SWFUpload can not read the login cookie, it can not send it either.

Flash has limited access to session cookies, as documented here in the SWFUpload forum. Is it possible that you've set the auto login to avoid setting an expiration (in config/tank_auth.php), thereby making it a session cookie? If that is the case, then the SWFUpload SWF may not be able to access or send the autologin cookie value, depending on the version of Flash player on the computer. Double-check your cookie expiration values using a debug tool like Firebug to see if this is the case. If the upload works when you check a "remember" me box but not otherwise, that would indicate a session cookie problem.

To force the SWF to pass the TankAuth cookie value on file uploads, you could first overload the cookie helper get_cookie function to look in either the $_COOKIE array or the $_POST array for values. Then, it appears that with SWFUpload v2 you can send additional POST values along with the upload, and this would be the way to send the autologin key, which would then allow your controller to get the user_id. But before hacking the Cookie helper, make sure your moving parts are working first, as described in the first paragraph.

诗笺 2024-10-13 16:14:17

我已经成功地对此进行了粗略的修复,方法是在 URL 中传递记录的用户 ID,并使用 URL 函数从 Javascript 获取它。这是我现在可以依赖的最好方法,用户 ID 可见并没有太困扰我,因为我使用托管 iframe 来显示应用程序的特定部分,并且该应用程序仅供公司内部使用。

感谢您的回答。

I have managed to apply a rough fix for this by passing the logged user ID in the URL, and getting it from Javascript with URL functions. It's the best method I can rely to right now, it doesn't bother me too much that the user ID is visible because I'm using a managed iframe to display that specific part of the app and the app is for internal company use only.

Thanks for your answers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文