2

我正在使用Codeigniter的会话类来创建 cookie 并将会话信息存储在我的数据库中,但是我在跨浏览器时遇到了问题。
看来我现在已经为除Firefox之外的所有浏览器提供了一切工作。该网站在用户登录后立即将用户踢出。我怀疑由于某种原因会话永远不会设置。

有什么建议吗?
网址:http: //www.nanp.org
下面的代码:

public function post() {
   $this->load->model('rbac/user');
   if($user = $this->user->user_by_column(array('email'=>$_POST['email'],'password'=>$_POST['password'],'verified'=>'true'))) {
      $this->session->set_userdata(array('user_id'=>$user->user_id));
      if($_POST['redirect']!='') {header('Location:'.$_POST['redirect']);}
      else {header('Location:members/dashboard');}
   }
   else {
      $this->data['php_error'] = 'Incorrect email or password.';
   }
}

这是我的会话配置信息:

$config['sess_cookie_name']     = 'nanpsession';
$config['sess_expiration']      = 2628000;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;

$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']      = "/";
$config['cookie_secure']    = FALSE;
4

3 回答 3

1

尝试使用2 equal signsif 语句:

 public function post() {
   $this->load->model('rbac/user');
   if($user == $this->user->user_by_column(array('email'=>$_POST['email'],'password'=>$_POST['password'],'verified'=>'true'))) {
     $this->session->set_userdata(array('user_id'=>$user->user_id));
     if($_POST['redirect']!='') {header('Location:'.$_POST['redirect']);}
     else {header('Location:members/dashboard');}
   }
   else {
    $this->data['php_error'] = 'Incorrect email or password.';
   }
}

更多关于 PHP If Statment 上一个等于的含义的信息:A php if statement with one equal sign...? 这是什么意思?

于 2013-01-17T21:42:59.740 回答
1

您如何确认会话不起作用。尝试打印任何会话变量或回显它,如果这返回空数组,那么您的会话可能无法正常工作。

 echo  print_r($this->session->set_userdata());

由于您说您的会话仅在Firefox上终止,可能是您在 Firefox 上配置了一些东西,因为它重置了会话变量。

于 2013-01-18T04:41:07.477 回答
0

Have you installed Firebug? It could cause the problem. Please refer to Firebug destroying session variables in Codeigniter application.

于 2013-10-16T12:17:42.533 回答