在CodeIgniter中设置Session_id [英] Setting Session_id in CodeIgniter

查看:275
本文介绍了在CodeIgniter中设置Session_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在标准PHP中,我可以通过以下方式设置会话ID:

In standard PHP i can set the session ID by following:

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

如何对CodeIgniter做同样的事?我尝试以下:

How can I do same with the CodeIgniter? I am trying following:

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

Am i making some mistake? Please help me as I have wasted several hours in this problem. If there is some issue with CodeIgniter Session class, can I use the standard PHP code to start session? I have tried to place the standard code in CodeIgniter as well, but it still does not set the session_id. I have also set $config['sess_match_useragent'] = FALSE;

推荐答案

p>这是我刚才建议的另一个问题。将它放置在 __结构的 MY_Session (未经测试,不能使用加密)

This is a hack I just suggested on another question. Place this in the __construct of MY_Session (untested 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()
}

这篇关于在CodeIgniter中设置Session_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆