2010-12-09 13:49
浏览 38

Codeigniter + TankAuth + Swfupload无法获取记录器用户ID

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()) {
        } else {
            $user_id = $this->tank_auth->get_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 ?

图片转代码服务由CSDN问答提供 功能建议

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

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

现在,它没有通过is_logged_in()检查,因为我从 其他帖子,CI删除会话但我已设置配置不匹配用户代理但仍然无法正常工作。


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • drmq16019 2011-01-05 01:43

    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:

    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 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,
    点赞 打赏 评论
  • douna6802 2011-01-04 23:54

    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.

    点赞 打赏 评论
  • dpmrakfbx820320638 2011-01-05 11:23

    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.

    点赞 打赏 评论

相关推荐 更多相似问题