2011-11-02 82 views
0

我使用kohana 3.2和我有会话数据库的问题,每当我在我的网站使用会话::实例()我得到一个新的数据库记录。还会话完全不工作,即使我一个新的值在登录页面Kohana 3.2 - 会话数据库

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 ::实例3次?

我是kohana的新手。但不是新的PHP。

感谢您的帮助

+0

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

回答

0

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

Cookie::$salt = 'YourSecretCookieSalt';