0

Currently I build single sign on of many website in my office, some of them are written with native PHP, I set global session with codeigniter, It's work properly between codeigniter app, but I try to read the session value in native PHP. Below is my code in Native PHP

ini_set('session.gc_maxlifetime', 7200);
ini_set('session.name', 'sso_session');
// this line caused login session destroyed (trying to set domain path)
session_set_cookie_params(
    7200,
    '/',
    '.myapp.local',
    FALSE,
    TRUE
);

ini_set('session.use_trans_sid', 0);
ini_set('session.use_strict_mode', 1);
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.sid_length', 32);
session_start();
print_r($_SESSION); // return empty array

I try to use Codeigniter session driver but I look inside the code, seem it's need dependencies of many codeigniter classes, too many changes that I need to modify the code.

Angga Ari Wijaya
  • 1,759
  • 1
  • 15
  • 31
  • If you just want to read, I don't think you need the `session_set_cookie_params` call. That would be for writing cookies. You should already be receiving the cookie that CodeIgniter set (`sso_session`?). You just need to use the data from that to locate and read the actual session data from wherever CodeIgniter has saved it. – Greg Schmidt Oct 29 '18 at 02:18
  • the only way to access CI sessions (that I am aware of based on research and my own experience) is to load the session driver which does indeed have dependencies OR ... – Alex Oct 29 '18 at 02:19
  • Possible duplicate of [Codeigniter 3 - Access Session from Outside Codeigniter Installation](https://stackoverflow.com/questions/31006756/codeigniter-3-access-session-from-outside-codeigniter-installation) – Alex Oct 29 '18 at 02:19
  • @GregSchmidt exactly, how do I locate the codeigniter session then, when I start session, it's automatically create PHPSESSION cookie, I try to set session id from codeigniter cookie, still session is empty – Angga Ari Wijaya Oct 29 '18 at 02:35
  • @Alex however I must include session driver from codeingiter right? – Angga Ari Wijaya Oct 29 '18 at 02:36
  • no you have two options, load the session driver and figure out the dependencies or do what is in the link – Alex Oct 29 '18 at 02:41
  • I've tried the link, include the core CI from one of the app and now it's working, thanks. – Angga Ari Wijaya Oct 29 '18 at 04:37

0 Answers0