ds342222222 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()) {
            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 ?

  • 写回答

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:

    <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,
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条