switching session settings in different controllers (same app)

#1
[eluser]Nick Jennings[/eluser]
Hi All,

I've got an application with a front-end and a back-end. The front-end bit is a short process which terminates the session after completion. The back-end bit is an admin interface.

Users who do not use the back-end will be using the front-end, however users who use the back-end will need to use the front-end as well.

The problem, is the session settings in config/config.php are applied to all session used in the app. So when an "admin" uses the front-end (when complete, the session is terminated), their back-end session is also terminated.

Admin users are authenticated from a different users table ('admins'), than the front-end users ('users').

Any suggestions on the best way to separate the session data so I can use a different cookie name and table table for front-end or back-end users?

Thanks,
-Nick

#2
[eluser]bigtony[/eluser]
I presume there is some kind of login process for the admin to access the back-end, so you could simply set a session variable so you know this has happened.
Code:
$this->session->set_userdata('admin', 1);
Then, condition your front-end so it only ends the session when the admin session variable is not set.
Code:
if (($this->session->userdata('admin') != 1):
    // End front end session stuff...
endif;

#3
[eluser]Nick Jennings[/eluser]
That solves the problem of keeping 'admins' logged in after using the front-end. However the front-end is a shopping cart like function and after the purchase has been completed all the session data needs to be destroyed, so the 'admin' could go back and re-do it as a new user.

So I would really need two sessions, as far as I can tell.. Is codeigniter limited to just one session setup per app?

Thanks,
Nick


[quote author="bigtony" date="1252498422"]I presume there is some kind of login process for the admin to access the back-end, so you could simply set a session variable so you know this has happened.
Code:
$this->session->set_userdata('admin', 1);
Then, condition your front-end so it only ends the session when the admin session variable is not set.
Code:
if (($this->session->userdata('admin') != 1):
    // End front end session stuff...
endif;
[/quote]


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.