Search code examples
phpsessionsubdomaincodeigniter-3

How to share session between multiple application in codeigniter


i have 2 client web and 2 admin dashboad web, which is developed on codeigniter. i want to share session between them. is it possible ?

this is the path structure:

main-path: --application 1
               --client web 
               --admin web
           --application 2
               --clinet web
           --application 3
               --admin web
           --system

this is the logics:

client web -> client web = only need one session,
admin web  -> admin web = only need one session

FYI: i am using subdomain in this porject url.

please enlight me. best regards


Solution

  • It's quite easy when your applications remain on the same domain.

    You can do it via session_set_cookie_params function, or via /application/config/config.php file, under the Cookie section.

    Edit the following lines.

    $config['cookie_prefix']    = 'yourdomain_';
    $config['cookie_domain']    = '.yourdomain.com'; //make it visible to all subdomains
    $config['cookie_path']      = '/';
    $config['cookie_secure']    = FALSE;
    $config['cookie_httponly']  = FALSE;
    

    Please note that if used, $config['encryption_key'] and $config['sess_cookie_name'] should have the same values on both applications.