CodeIgniter Forums
Your thoughs on seperate frontend and backend sessions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Your thoughs on seperate frontend and backend sessions (/showthread.php?tid=66030)



Your thoughs on seperate frontend and backend sessions - wolfgang1983 - 08-26-2016

Hello When I use have set session in the past for front end and admin I have set them like

Code:
$this->session->set_userdata('admin', array('some admin array items'));

And

Code:
$this->session->set_userdata('catalog', array('some front end array items'));

But I was thinking if could do it this way

My question is. Is the way below OK?

PHP Code:
$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$segments explode('/'$_SERVER['REQUEST_URI_PATH']);

$config['sess_driver'] = 'files';

if (
$segments[2] == 'admin') {

    
$config['sess_cookie_name'] = 'admin_sessions';
    
$config['sess_expiration'] = 1440;
    
$config['sess_save_path'] = FCPATH 'application/cache/session/admin/';

} else {

    
$config['sess_cookie_name'] = 'catalog_sessions';
    
$config['sess_expiration'] = 7200;
    
$config['sess_save_path'] = FCPATH 'application/cache/session/catalog/';

}

$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE



RE: Your thoughs on seperate frontend and backend sessions - rtenny - 08-26-2016

(08-26-2016, 12:14 AM)wolfgang1983 Wrote: Hello When I use have set session in the past for front end and admin I have set them like

Code:
$this->session->set_userdata('admin', array('some admin array items'));

And

Code:
$this->session->set_userdata('catalog', array('some front end array items'));

But I was thinking if could do it this way

My question is. Is the way below OK?

PHP Code:
$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$segments explode('/'$_SERVER['REQUEST_URI_PATH']);

$config['sess_driver'] = 'files';

if (
$segments[2] == 'admin') {

    
$config['sess_cookie_name'] = 'admin_sessions';
    
$config['sess_expiration'] = 1440;
    
$config['sess_save_path'] = FCPATH 'application/cache/session/admin/';

} else {

    
$config['sess_cookie_name'] = 'catalog_sessions';
    
$config['sess_expiration'] = 7200;
    
$config['sess_save_path'] = FCPATH 'application/cache/session/catalog/';

}

$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE

This is actually a cool idea.
I cannot see anything wrong and I will give this a try myself.

Thanks for sharing


RE: Your thoughs on seperate frontend and backend sessions - Wouter60 - 08-26-2016

Very good indeed.
One thing though. Why do you 'calculate' the segment yourself?
The URI class (which is automatically initialized) will do that for you.
See: http://www.codeigniter.com/userguide3/libraries/uri.html


RE: Your thoughs on seperate frontend and backend sessions - wolfgang1983 - 08-26-2016

(08-26-2016, 11:57 AM)Wouter60 Wrote: Very good indeed.
One thing though. Why do you 'calculate' the segment yourself?
The URI class (which is automatically initialized) will do that for you.
See: http://www.codeigniter.com/userguide3/libraries/uri.html

Because I can't load uri->segments into the config.php file.