Session sharing between two CodeIgniter Applications

后端 未结 6 1022
失恋的感觉
失恋的感觉 2021-01-15 16:41

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

<
相关标签:
6条回答
  • 2021-01-15 16:49

    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.

    0 讨论(0)
  • 2021-01-15 16:50
    $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
        )
    

    )

    0 讨论(0)
  • 2021-01-15 16:57
    $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.

    0 讨论(0)
  • 2021-01-15 16:58

    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..

    0 讨论(0)
  • 2021-01-15 17:00

    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.

    0 讨论(0)
  • 2021-01-15 17:08

    If you move the code to the same server ,both the sessions will start to share by default.

    0 讨论(0)
提交回复
热议问题