【问题标题】:How to get kohana session data outside kohana application?如何在 kohana 应用程序之外获取 kohana 会话数据?
【发布时间】:2013-05-18 11:12:26
【问题描述】:

我想在 kohana 应用程序之外获取 kohana 会话数据。我的意思是说我想在不是 kohana 页面的静态文件中获取会话数据。

【问题讨论】:

    标签: php session kohana-3.2


    【解决方案1】:

    我尝试了很多东西,最后我找到了答案,

    在您的控制器类中,在 kohana 会话实例之前获取本机会话 ID 并将其存储。现在关闭本机会话并通过将会话 ID 作为参数传递来启动 kohana 会话。

        session_start();    
        // Store session id and close the session
        $sessionId = session_id();
        session_write_close();
    
        // Then we can restore the session by using the session id 
        // and the Session class from Kohana
        Session::Instance(Session::$default, $sessionId);
    

    现在您可以在 kohana 应用程序中访问会话。

    【讨论】:

      【解决方案2】:
      session_name('kohana'); //Your session name   
      print_r($_SESSION);
      

      您可以通过在APPPATH/config/session.php 创建会话配置文件,将配置设置应用于每个会话适配器。以下示例配置文件定义了每个适配器的所有设置:

      [!!] 与 cookie 一样,“生命周期”设置为“0”意味着会话将在浏览器关闭时过期。

      return array(
          'native' => array(
              'name' => 'session_name',
              'lifetime' => 43200,
          ),
          'cookie' => array(
              'name' => 'cookie_name',
              'encrypted' => TRUE,
              'lifetime' => 43200,
          ),
          'database' => array(
              'name' => 'cookie_name',
              'encrypted' => TRUE,
              'lifetime' => 43200,
              'group' => 'default',
              'table' => 'table_name',
              'columns' => array(
                  'session_id'  => 'session_id',
                  'last_active' => 'last_active',
                  'contents'    => 'contents'
              ),
              'gc' => 500,
          ),
      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-07
        • 1970-01-01
        • 1970-01-01
        • 2019-08-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多