Codeigniter two project same session directory

1.4k Views Asked by At

I want to use same directory (for 2 project) for codeigniter "files" session driver. Both projects are in same server.

project 1 save path settings

$config['sess_save_path'] = APPPATH.'session_data';

project 2 save path settings

$config['sess_save_path'] = $_SERVER['DOCUMENT_ROOT'].'/project1/application/session_data';

This is working locally but not working in production server. Whats wrong there? My "session_data" directory permission is "755". 777 tested but not work

2

There are 2 best solutions below

0
On

In simple write the same value for both the files in config.php

 $['encryption_key'] = 'ci_sesion';
 $config['sess_cookie_name'] = 'ci_session';
 $config['csrf_token_name'] = 'csrf_test_name';
 $config['csrf_cookie_name'] = 'csrf_cookie_name';

I did and getting my output like move from one project to another project using same session.

Suppose you need to create two different project having different session then change the value of given above variables.

1
On

Store your session in DB, and use the same DB for both projects.

Codeiniter 2+:

$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';

Codeiniter 3+:

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

Codeigniter 2 MySQL:

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
    session_id varchar(40) DEFAULT '0' NOT NULL,
    ip_address varchar(45) DEFAULT '0' NOT NULL,
    user_agent varchar(120) NOT NULL,
    last_activity int(10) unsigned DEFAULT 0 NOT NULL,
    user_data text NOT NULL,
    PRIMARY KEY (session_id),
    KEY `last_activity_idx` (`last_activity`)
);

Codeigniter 3 MySQL:

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`)
);

Just Make sure your $config['encryption_key'] is same for both projects.