CodeIgniter Forums

Full Version: Get current system user
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hi all,

I am try to get current sytem user, ex: Administrator, guest etc.
Is there a way to do this in CodeIgniter or in PHP?


El Forum

[eluser]Pascal Kriete[/eluser]
Sure it is, lots of authentication libraries do this. However, it is totally up to you how you'll do this, because only you know what defines each of these roles. If you need more granularity you could also look into using an ACL.

El Forum

The very general overview of how this is achieved is to store the user_id and role in a session var when the user logs in. Then for each controller you need protecting put calls to code that check the allowed roles against the role in the session var then, once authorized, use the user_id to grab the relevant user record(s) from the db.
Of course within that basic structure there are hundreds of possible variations. How you achieve it is entirely up to you.