Php 还原CodeIgniter中的会话\u id

Php 还原CodeIgniter中的会话\u id,php,session,codeigniter,Php,Session,Codeigniter,我想销毁并恢复会话id,然后启动会话,这是在标准PHP中完成的,如下所示。如何在CodeIgniter中执行此操作 session_destroy(); session_id($old_session_id); session_start(); 我认为会话是通过自动加载库自动启动的: $autoload['libraries'] = array('session'); 是这样吗?如何使用会话id($old\u session\u id)在CodeIgniter中? 我正在尝试使用$this-

我想销毁并恢复会话id,然后启动会话,这是在标准PHP中完成的,如下所示。如何在CodeIgniter中执行此操作

session_destroy();
session_id($old_session_id);
session_start();
我认为会话是通过自动加载库自动启动的:

$autoload['libraries'] = array('session');
是这样吗?如何使用
会话id($old\u session\u id)在CodeIgniter中?
我正在尝试使用
$this->session->set\u userdata('session\u id',$old\u session\u id)

但似乎有些东西工作不正常,因为我无法获取会话数据。你知道上面这几行有什么问题吗?
谢谢。

有些东西需要检查:

  • 检查以确保会话在没有CodeIgniter的情况下在PHP中工作。如果会话不工作,则服务器未正确保存会话信息

  • 检查是否将会话信息保存到数据库中(在application/config/config.php中,$config['sess_use_database']是否等于FALSE?如果为TRUE,请确保将此代码导入数据库中

  • 如果此处出现错误,则CI不保存会话信息

  • 在正常工作的控制器函数中使用此代码段,尝试进行更多的会话测试:
  • 检查错误日志,查看CI是否正在加载会话库模块,并且不存在任何错误


    这与其说是一个解决方案,不如说是一种会话调试策略。

    CodeIgniter中的会话与nativ PHP会话不同。实际上,它们根本不是会话,因为它们实际上是加密cookie(您也可以使用数据库存储会话值,但它们与PHP会话不同)

    从手册中引用: 什么是会话数据

    A session, as far as CodeIgniter is concerned, is simply an array containing the following information:
    
        The user's unique Session ID (this is a statistically random string with very strong entropy, hashed with MD5 for portability, and regenerated (by default) every five minutes)
        The user's IP Address
        The user's User Agent data (the first 50 characters of the browser data string)
        The "last activity" time stamp.
    
    The above data is stored in a cookie as a serialized array with this prototype: [array] (
         'session_id'    => random hash,
         'ip_address'    => 'string - user IP address',
         'user_agent'    => 'string - user agent data',
         'last_activity' => timestamp )
    
    无论何时加载页面,CI都会检查Cookie以查看是否存在会话。如果没有(因为您没有设置会话,或者因为会话已过期),则将创建会话。如果存在会话,CI将自动重新生成会话

    如果您想使用CI的本机会话,这就是方法。否则,您可以使用本机php会话(框架非常灵活),但不能将两者混合使用,因为它们作用于不同的级别(在php服务器上,在CI会话客户端上)

    $this->load->library('session'); // load session in controller
    echo $session_id = $this->session->userdata('session_id'); // print session id to page
    
    A session, as far as CodeIgniter is concerned, is simply an array containing the following information:
    
        The user's unique Session ID (this is a statistically random string with very strong entropy, hashed with MD5 for portability, and regenerated (by default) every five minutes)
        The user's IP Address
        The user's User Agent data (the first 50 characters of the browser data string)
        The "last activity" time stamp.
    
    The above data is stored in a cookie as a serialized array with this prototype: [array] (
         'session_id'    => random hash,
         'ip_address'    => 'string - user IP address',
         'user_agent'    => 'string - user agent data',
         'last_activity' => timestamp )