简体   繁体   中英

Session sharing between two CodeIgniter Applications

I have 2 codeigniter installs running on the same server.

the first app is : localhost/aa/index.php

second app is : localhost/aa/invoice/index.php

The second app is in the first app folder. In the live environment, they will be on the same domain. I am trying to get a single sign-on to work -- so, if i have userdata set in the aa application I should be able to verify it in the invoice folder also.

Is there a way to share the sessions.

As the folders will always be on the same domain, I am open to working with sessions outside the ci library(only php) also.

They show the same session id when they don't have any data. 当他们没有任何数据时,它们显示相同的会话ID。 The moment I add some variables on one application, the other goes out of sync.

Also I have sessions being stored in the database(both applications share the same database.)

Please suggest.

Thanks! : )

Codeigniter for some reason rolls its own session implementation rather than native PHP sessions.

http://codeigniter.com/user_guide/libraries/sessions.html

You get a choice of using:

  1. cookie storage (not ideal, small storage size, sensitive data in a cookie?).
  2. database sessions (persisted using session id cookie).
  3. Override and roll your own (to use native php sessions!)

Obviously you need to make sure your session identifier is configured correctly so both apps can read from the same session data. If using the database implementation, you need to make sure both apps can access the same DB.

To add to the complexity, if you choose to encrypt sessions, the salt used by the encryption class will also need to be the same in both apps, so either one is able to decrypt the shared session data.

$config['encryption_key'] = 'epitome';

The encryption_key configuration name will be the same for both the application folders.

Path to change the encryption_key in codeigniter is application/config/config.php Line number 228.

$config['sess_cookie_name'] = 'myvalue';

In config.php file you can set the same value on both CI Apps., with 'file' Session Drivers

CI_Session Object

( [userdata] => Array ( [__ci_last_regenerate] => 1490351129 [Level] => 1 [User] => 103 [Fullname] => Ruben Caldera )

[_driver:protected] => files
[_config:protected] => Array
    (
        [cookie_lifetime] => 600
        [cookie_name] => MyHiddenValue
        [cookie_path] => /
        [cookie_domain] => 
        [cookie_secure] => 
        [expiration] => 600
        [match_ip] => 
        [save_path] => /tmp
    )

)

If I may .... I have noted that those design problems which are not practical and goes against the normal convention shall provided a basis for long and deep rooted problems.... You should ask your self it is really necessary / advisable to share session data between 2 different version of a framework when we know they are 2 different version for the reason that they do things differently... I can only say that no matter what you do.. this design flaw shall make your architecture fragile and sooner or later you will have to dump it.

Plz let me know if later you find out otherwise..

If you install the code on the same Server using the same encryption key, By default, both installation will share session. Actually, I discovered when I copied a codeigniter installation for another client but on the same server. I thought it was a bug as I was worried.

如果将代码移到同一服务器上,则默认情况下,两个会话都将开始共享。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM