Setting Session_id in CodeIgniter

In standard PHP, I can set the session identifier as follows:

$my_session_id = $_GET['session_id']; //gets the session ID successfully session_id($my_session_id); //sets the session with my session_id session_start(); //starts session. 

How can I do this with CodeIgniter? I am doing my best:

 $my_session_id = $_GET['session_id']; //gets the session ID successfully $this->session->userdata('session_id', $my_session_id); //it won't set the session with my id. print_r($this->session->userdata); 

Am I mistaken? Please help me as I spent several hours on this issue. If there is any problem with the SessionIgniter Session class, can I use the standard PHP code to start the session? I tried to put the standard code in CodeIgniter, but it still does not set session_id. I also set $config['sess_match_useragent'] = FALSE;

+4
source share
4 answers

This is the hack I just suggested on another question . Put this in __construct from MY_Session (unverified and will not work with encryption)

 public function __construct() { if( isset( $_GET['session_id'] ) ) $_COOKIE[ $this->sess_cookie_name ] = $_GET['session_id']; // Session now looks up $_COOKIE[ 'session_id' ] to get the session_id parent::__construct() } 
0
source

You do not need to do this, codeigniter does everything for you.

If you want to get the session id, you can do this by calling:

 $session_id = $this->session->userdata('session_id'); 

However, you can get around this: (note that this post is 3 years old, and I'm not sure if it is still needed)

http://mumrah.net/2008/06/codeigniter-session-id/

+6
source

use this to set session_id in codeigniter:

 $this->session->set_userdata( array('session_id', $your_session_id) ); 

and

 $session_id = $this->session->userdata('session_id'); 

for repeated reading.

0
source

You should always start a session before changing any session variables.

I believe that to start a CodeIgniter session, you can do the following:

 $this->load->library('session'); $my_session_id = $_GET['session_id']; //gets the session ID successfully $this->session->userdata('session_id', $my_session_id); //it won't set the session with my id. print_r($this->session->userdata); 
0
source

All Articles