【问题标题】:Codeigniter sessions in firefox won't setFirefox 中的 Codeigniter 会话不会设置
【发布时间】:2013-10-16 20:17:42
【问题描述】:

我正在使用 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;

【问题讨论】:

    标签: codeigniter session firefox


    【解决方案1】:

    在 if 语句中尝试使用 2 equal signs

     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 语句中一等的含义的信息:A php if statement with one equal sign...? What does this mean?

    【讨论】:

    • 不要认为这是我的问题。我没有在那里检查是否相等,这不是浏览器问题,而是 PHP 问题,所以如果这是问题,它将出现在所有浏览器中,而不仅仅是 firefox。
    【解决方案2】:

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

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

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

    【讨论】:

    • 是的,我一直在“set_userdata”行之后打印会话数据。对于某些 Firefox 用户,Codeigniter 会话数组的“userdata”键是空的。有趣的是,使用 Firefox 对我来说一切正常 - 其他用户也遇到了问题。
    【解决方案3】:

    您安装了 Firebug 吗?这可能会导致问题。请参考Firebug destroying session variables in Codeigniter application

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-20
      相关资源
      最近更新 更多