CodeIgniter Forums

Full Version: ci_session with multiple database not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am working on a project where using two databases. My requirement is that, Depending on user login type load database e.g.

For user type 1 load db1(default database) Or For user type 2 load db2. Problem is that if login with user type 1 then logged in successfully but if login with user type 2 then login failed due to the ci_session table. how to fix this issue.
@samtron,

Why don't you initiate the session after the user is verified? If the login fails then simply send an error message and don't start the session.
(05-02-2019, 06:53 PM)php_rocs Wrote: [ -> ]@samtron,

Why don't you initiate the session after the user is verified?  If the login fails then simply send an error message and don't start the session.

You means don't use autoload session?
@samtron,

Correct. You can wait to initialize a session after the user has successfully logged into the application.
(05-02-2019, 06:53 PM)php_rocs Wrote: [ -> ]Why don't you initiate the session after the user is verified?  If the login fails then simply send an error message and don't start the session.

Because the session is used to identify someone who has successfully logged in but has been redirected to, or has navigated to some other page.
(05-03-2019, 05:28 AM)php_rocs Wrote: [ -> ]@samtron,

Correct.  You can wait to initialize a session after the user has successfully logged into the application.

Ok, Thankyou
(05-02-2019, 01:17 PM)samtron Wrote: [ -> ]Problem is that if login with user type 1 then logged in successfully but if login with user type 2 then login failed due to the ci_session table. how to fix this issue.

The fix is to not use
PHP Code:
$config['sess_driver'] = 'database'

Any other driver will work.
(05-03-2019, 08:01 AM)dave friend Wrote: [ -> ]
(05-02-2019, 01:17 PM)samtron Wrote: [ -> ]Problem is that if login with user type 1 then logged in successfully but if login with user type 2 then login failed due to the ci_session table. how to fix this issue.

The fix is to not use
PHP Code:
$config['sess_driver'] = 'database'

Any other driver will work.

Any example?
(05-03-2019, 08:51 AM)samtron Wrote: [ -> ]Any example?

'files', ‘memcached’, or , 'redis'

I usually use 'files'. It's easy to implement and proven to be responsive even on sites with daily session hits in the hundreds of thousands. If you need to handle millions of sessions a day then you want a memcached setup - and a better system admin than me.