code igniter passing database session_id in view

2019-02-11 07:35发布

问题:

I am trying to get Uploadify working with code igniter however am having the same problem as everyone with a new session being created for "ShockWave Flash" instead of picking up the already created session.

I have the following setttings set

$config['sess_cookie_name']     = 'session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'sessions';
$config['sess_match_ip']        = TRUE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update']  = 300;

The Code Igniter session table is like so WITH BROWSER

   session_id: 73b05af777af0e6a56e7bbba8f9714f6
   ip_address: 127.0.0.1
   user_agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/53
last_activity: 1310341663
    user_data: a:6:{s:5:"email";s:32:"test@hotmail.com"}

WITH UPLOADIFY

   session_id: d39bce3d9c734081379b286449cf56ce
   ip_address: 127.0.0.1
   user_agent: Shockwave Flash
last_activity: 1310341167
    user_data: 

I'm trying to hack this and add the browser session_id as a get to the php like so so when uploadify submits I can retrieve user session data given the session id.

              $(document).ready(function() {   
                $('#uploadify').uploadify({  
                  'uploader'  : '/uploadify/uploadify.swf',   
                  'script'    : '/index.php/upload/uploadify/'.$this->session->userdata('session_id').'',  

My question is: 1) is it bad that I am showing the session_id publicly in the source, is that session_id available regardless even if I don't do this? 2) On the "upload" controller, how can I essentially "load" that session_id or get data out from it?

回答1:

  1. The only way that would pose a problem is if you're encrypting the session_id cookie -- otherwise, you're not giving the user any more real data. (So, yes, in most cases, they can get that data anyway)
  2. You will need to overwrite sess_read() or __construct in your MY_Session class to look at a custom variable or you could modify the cookie

Basically this:

public function __construct( $id )
{
   // a hack, but you need a hack
   $_COOKIE[ $this->sess_cookie_name ] = $id;
   parent::__construct();
}