2017-03-15 71 views
0

我一直在使用ion_auth与笨的系统3年。突然之间的会议没有按照他们应该做的那样工作。Ion_auth - 在一个会话多个用户

当用户A登录到网站,他们的会话似乎与所有其他用户共享。因此,当用户B导航到任何路由时,他们都会以用户A的凭证“登录”。

我已经用多个用户测试了这一点,只要用户登录到网站,所有其他访问该网站的用户都会自动使用该用户的凭证/会话登录。

如果用户注销并且调用auth/logout路由,则会话不会被销毁,所有用户都会保持登录该会话。

登录后的初始重定向进入/车辆/索引。一旦你导航到任何其他页面,检查用户是否登录,你被重定向登录。

主控制器代码:

public function vehicle() 
{ 

    if (!$this->ion_auth->logged_in()) 
    { 
     redirect('auth/login'); 
    } 
    else { 
     if (!$this->ion_auth->is_admin()) { 

      /** 
      * 
      * User IS NOT admin 
      * 
      **/ 
      // Get User_id if standard user 
      $user = $this->ion_auth->user()->row(); 
      // Build Crud 

控制器auth.php

public function logout() 
{ 
    $this->data['title'] = "Logout"; 

    // log the user out 
    $logout = $this->ion_auth->logout(); 

    // redirect them to the login page 
    $this->session->set_flashdata('message', $this->ion_auth->messages()); 
    redirect('auth/login', 'refresh'); 
} 

服务器PHP版本30年6月5日 - 生成日期2017年2月3日7时51分58秒

笨2.2版0.1 - 版本没有改变

Ion_Auth配置:

$config['hash_method'] = 'bcrypt'; // sha1 or bcrypt, bcrypt is 

STRONGLY recommended 
$config['default_rounds'] = 8;  // This does not apply if random_rounds is set to true 
$config['random_rounds'] = FALSE; 
$config['min_rounds']  = 5; 
$config['max_rounds']  = 9; 
$config['salt_prefix'] = version_compare(PHP_VERSION, '5.3.7', '<') ? '$2a$' : '$2y$'; 

/* 
| ------------------------------------------------------------------------- 
| Authentication options. 
| ------------------------------------------------------------------------- 
| maximum_login_attempts: This maximum is not enforced by the library, but is 
| used by $this->ion_auth->is_max_login_attempts_exceeded(). 
| The controller should check this function and act 
| appropriately. If this variable set to 0, there is no maximum. 
*/ 
$config['site_title']     = "Cars in the park";  // Site Title, example.com 
$config['admin_email']    = "[email protected]"; // Admin Email, [email protected] 
$config['default_group']    = 'members';   // Default group, use name 
$config['admin_group']    = 'admin';    // Default administrators group, use name 
$config['identity']     = 'email';    // A database column which is used to login with 
$config['min_password_length']  = 8;     // Minimum Required Length of Password 
$config['max_password_length']  = 20;     // Maximum Allowed Length of Password 
$config['email_activation']   = TRUE;    // Email Activation for registration 
$config['manual_activation']   = TRUE;    // Manual Activation for registration 
$config['remember_users']    = FALSE;    // Allow users to be remembered and enable auto-login 
$config['user_expire']    = 30;    // How long to remember the user (seconds). Set to zero for no expiration 
$config['user_extend_on_login']  = FALSE;    // Extend the users cookies every time they auto-login 
$config['track_login_attempts']  = TRUE;    // Track the number of failed login attempts for each user or ip. 
$config['track_login_ip_address']  = TRUE;    // Track login attempts by IP Address, if FALSE will track based on identity. (Default: TRUE) 
$config['maximum_login_attempts']  = 3;     // The maximum number of failed login attempts. 
$config['lockout_time']    = 600;     // The number of seconds to lockout an account due to exceeded attempts 
$config['forgot_password_expiration'] = 0;     // The number of milliseconds after which a forgot password request will expire. If set to 0, forgot password requests will not expire. 

会话配置:

$config['sess_cookie_name']  = 'ci_session'; 
$config['sess_expiration']  = 30; 
$config['sess_expire_on_close'] = TRUE; 
$config['sess_encrypt_cookie'] = FALSE; 
$config['sess_use_database'] = FALSE; 
$config['sess_table_name']  = 'ci_sessions'; 
$config['sess_match_ip']  = FALSE; 
$config['sess_match_useragent'] = FALSE; 
$config['sess_time_to_update'] = 30; 

会话变量(登录的用户。所有其他用户在会话中的相同信息):

stdClass Object ([id] => 1148 [ip_address] => [username] => testing [password] => $2y$08$Q4fjUfsuOKM/Q8cnQt6j0uSXP.3mCqMnzDY1nBA9RDlwm [salt] => sadsda [email] => [email protected] [activation_code] => [forgotten_password_code] => [forgotten_password_time] => [remember_code] => [created_on] => 1426181328 [last_login] => 1490008619 [active] => 1 [first_name] => Name [last_name] => Testing [company] => [phone] => [user_id] => 1148) 
+0

您是否执行CI升级,是否在您的服务器上升级了php?请检查所有可能的配置更改并将其编辑为您的问题。谢谢 – Vickel

+0

如果它曾经工作过,并且你没有编辑代码,那么你描述的是不可能的......尽管已经正确安装了Ion Auth,共享相同会话的两个用户已经不太可能了。检查文件修改日期以验证没有人篡改任何内容。另外,我对你如何测试这个问题非常怀疑......你是否使用不同的机器和/或浏览器来验证这些观察结果? – Sparky

+0

我在不同的设备上测试了这一点,不同的连接和结果保持不变。一个会话被创建并且每个人都停留在那个会话上直到它到期。注销不会销毁会话,但logged_in()返回false,所以所有页面在第一次重定向后重定向回登录。 –

回答

0

变化配置如下设置:

$config['sess_driver'] = 'database'; 
$config['sess_save_path'] = 'ci_sessions'; 

创建表ci_sessions

对于MySQL:

DROP TABLE IF EXISTS `ci_sessions`; 

CREATE TABLE IF NOT EXISTS `ci_sessions` (
    `id` varchar(128) NOT NULL, 
    `ip_address` varchar(45) NOT NULL, 
    `timestamp` int(10) unsigned DEFAULT 0 NOT NULL, 
    `data` blob NOT NULL, 
    KEY `ci_sessions_timestamp` (`timestamp`) 
); 

对于PostgreSQL:

CREATE TABLE "ci_sessions" (
    "id" varchar(128) NOT NULL, 
    "ip_address" varchar(45) NOT NULL, 
    "timestamp" bigint DEFAULT 0 NOT NULL, 
    "data" text DEFAULT '' NOT NULL 
); 

CREATE INDEX "ci_sessions_timestamp" ON "ci_sessions" ("timestamp"); 

使用的数据库为您的会话驱动

“数据库”驱动程序用来存储会话关系数据库如MySQL或PostgreSQL。这是许多用户的流行选择,因为它允许开发人员在应用程序中轻松访问会话数据 - 它只是数据库中的另一个表。

然而,也有一些条件必须满足:

  • 只有你默认的数据库连接(或从您的控制器访问为$this->db的)都可以使用。
  • 您必须具有启用查询生成器
  • 您可以不是使用一个持续连接
  • 您可以不是使用连接与cache_on设置启用

来源:Codeigniter Session

0

这是一个服务器的问题(共享主机)。我将完整的应用程序移动到一个新的主机(vps主机),一切都像以前一样工作。

更改为DB会话Rafiq和其他评论员的建议确实有助于测试。