【问题标题】:Kohana 3.2 - Session databaseKohana 3.2 - 会话数据库
【发布时间】:2011-11-02 11:57:25
【问题描述】:

我使用 kohana 3.2 并且会话数据库有问题,每次我在我的站点中使用 Session::Instance() 时,我都会得到一个新的数据库记录。即使我为其设置了新值,会话也根本不起作用

在登录页面

public function action_index()
{
    if ( Session::instance()->get('logged'))
        $this->request->redirect('home');


    $this->response->body(View::factory('pages/login'));

}

在认证功能中

public function action_authenticate()
{
    $username = $this->request->post('username');
    $password = $this->request->post('password');

    $user = ORM::factory('user');
    $data = $user->user_login($username, $password);

    if ( $data == $username){


         Session::instance()->set('logged', true);

         $this->request->redirect('home');

    }
    else
    {
        echo "incorrect username or password";
    }

如果未设置登录,则在主页中我只是重定向回登录

 function action_index(){

    if (  ! Session::instance()->get('logged'))
        $this->request->redirect('login');


   $this->template->header = View::factory('pages/header')->render();
   $this->template->footer = view::factory('pages/footer')->render();
   $data['sidebar'] = View::factory('pages/sidebar')->render();
   $this->template->content = View::factory('pages/home',$data);

}

在 bootstrap.php 中我添加了 Session::$default = 'database';所以它默认使用数据库。 如果我删除数据库模式它工作得很好,如果它在那里我得到所有时间 3 数据库记录,因为我调用 Session::instance 3 次?

我是 kohana 的新手。但对 php 并不陌生。

感谢帮助

【问题讨论】:

  • 检查您的 cookie。会话 cookie 是否已设置? cookie中的session_id是不是每个请求都不一样?

标签: session kohana


【解决方案1】:

在 bootstrap.php 中设置 Cookie::$salt。在 bootstrap.php 中添加这一行。

Cookie::$salt = 'YourSecretCookieSalt';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多