Welcome Guest, Not a member yet? Register   Sign In
Your thoughs on seperate frontend and backend sessions
#1

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
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

(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
On the package it said needs Windows 7 or better. So I installed Linux.
Reply
#3

(This post was last modified: 08-26-2016, 11:57 AM by Wouter60.)

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/li...s/uri.html
Reply
#4

(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/li...s/uri.html

Because I can't load uri->segments into the config.php file.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB