CI中

2011-07-11 25 views
4

設置SESSION_ID在標準的PHP我可以通過以下設置會話ID:CI中

$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. 

我該怎麼做同樣的用笨?我正在嘗試以下方法:

$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); 

我是否犯了一些錯誤?請幫助我,因爲我在這個問題上浪費了幾個小時。如果CodeIgniter Session類存在問題,我可以使用標準PHP代碼來啓動會話嗎?我試圖在CodeIgniter中放置標準代碼,但它仍然沒有設置session_id。我也設置了$config['sess_match_useragent'] = FALSE;

回答

0

這是我剛纔在另一個question上建議的黑客攻擊。把這個在MY_Session__construct(未經測試,不會與加密工作)

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

謝謝,我不有MY_Session文件,我是否需要在CodeIgniter的庫文件夾或Core文件夾中創建MY_Session.php文件?在創建併發布此代碼之後,我將如何調用MY_Session? (對不起,我是CodeIgniter或任何框架的新手) – Roman

+0

如果您將MY_Session.php文件放在您的庫文件夾中,它將被用來代替CI_Session – cwallenpoole

6

你不應該這樣做,codeigniter爲你做這一切。

如果你想通過調用獲取會話ID,你可以這樣做:

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

但是你可以解決它:(注意:這個職位是3歲,我不確定它是否仍然是必要的)

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

0

使用這種在笨設置SESSION_ID:

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

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

用於再次讀出它。

+0

這將設置我的會話ID與'SESSION_ID [1]',連我都放在這上一行:'$這個 - >會話級> unset_userdata( 'SESSION_ID');' – Roman

0

你總是應該修改任何會話變量之前啓動會話。

我相信要啓動CodeIgniter會話,您可以執行以下操作;

$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

謝謝,但我會自動加載會話庫。 – Roman