I have a web app which is in Core PhP. And we are moving it to CI Framework step by step.
Problem: Need to share session value between them.
Core PHP App Dir Structure:|-- /xampp/lms/
Core PHP App URL: http://localhost/
lms/index.php
CI App Dir Structure: |-- /xampp/lms/newlms/
CI App URL: http://localhost/lms/
newlms/index.php/login
CI Configuration:
config.php
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
What I have did so far.
Core PHP changes
Path: \xampp\htdocs\lms\configuration.inc.php
(this is file called first in core php)
session_name('ci_session');
session_start();
echo '<pre>';
echo '<br/>------------- session_save_path-------- <br/>';
print_r(session_save_path());
echo '<br/>------------- session_name-------- <br/>';
print_r(session_name());
echo '<br/>------------- $_COOKIE -------- <br/>';
print_r($_COOKIE);
echo '<br/>------------- $_SESSION -------- <br/>';
print_r($_SESSION);
exit;
output:
------------- session_save_path--------
\xampp\tmp
------------- session_name--------
ci_session
------------- $_COOKIE --------
Array (
[ci_session] => 2b9tj8rek53kapgsuh4k3v2fuuvblvq9
)
------------- $_SESSION --------
Array (
some values which I have set in Core php
)
Session Path xampp\tmp\sess_2b9tj8rek53kapgsuh4k3v2fuuvblvq9
CI changes
path: \xampp\htdocs\lms\newlms\application\modules\login\controllers
Class Login extends MX_Controller {
function __construct() {
parent::__construct();
}
function index() {
echo '<pre>';
echo '<br/>------------- session_save_path-------- <br/>';
print_r(session_save_path());
echo '<br/>------------- session_name-------- <br/>';
print_r(session_name());
echo '<br/>------------- $_COOKIE -------- <br/>';
print_r($_COOKIE);
echo '<br/>------------- $_SESSION -------- <br/>';
print_r($_SESSION);
exit;
}
}
output:
------------- session_save_path--------
\xampp\tmp
------------- session_name--------
ci_session
------------- $_COOKIE --------
Array (
[ci_session] => 2b9tj8rek53kapgsuh4k3v2fuuvblvq9
)
------------- Core $_SESSION --------
Array (
[__ci_last_regenerate] => 1479978675
)
------------- CI $_SESSION --------
CI_Session Object (
.. Some values.
)
PS: I have tried to explain in best way but Before Down Voting please share the reason.
As suggested by bertmaclin,
CI's session handler is just a wrapper of the php session handler
Have tweek CI's config.php & session Library.
CI config.php: added given code just before base_url
configuration.
session_start();
CI Session.php: added @ before session_start()
in session library line #142.
@session_start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With