Session Kohana 3.2-会话数据库
我使用的是kohana 3.2,会话数据库有问题,每次在我的站点中使用session::Instance()时,我都会得到一个新的数据库记录。而且,即使我设置了一个新值,会话也根本不起作用 在登录页面中Session Kohana 3.2-会话数据库,session,kohana,Session,Kohana,我使用的是kohana 3.2,会话数据库有问题,每次在我的站点中使用session::Instance()时,我都会得到一个新的数据库记录。而且,即使我设置了一个新值,会话也根本不起作用 在登录页面中 public function action_index() { if ( Session::instance()->get('logged')) $this->request->redirect('home'); $this->res
public function action_index()
{
if ( Session::instance()->get('logged'))
$this->request->redirect('home');
$this->response->body(View::factory('pages/login'));
}
在auth函数中
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";
}
在主页中,如果未设置logged,我只需重定向回login
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中,我添加了会话::$default='database';所以它默认使用数据库。
如果我删除数据库模式,它工作得很好,如果它在那里,我会得到所有的时间3个数据库记录,因为我调用了会话::实例3次
我是科哈纳的新手。但对php来说并不陌生
感谢您的帮助在bootstrap.php中设置Cookie::$salt。在bootstrap.php中添加这一行
Cookie::$salt = 'YourSecretCookieSalt';
检查你的饼干。会话cookie是否已设置?cookie中的会话id是否随每个请求而不同?