Welcome Guest, Not a member yet? Register   Sign In
How to implement codeigniter login system ?

Earlier i used to check logins in PHP using

and used to put this code on top of every page that had to be login protected.

But now, how do i implement this in codeigniter ?

Do i have to do a session variable check inside every controller like this ? or is there a better way ?

class Gallery extends Controller  {
      function index() {
               // controller code here

There are a few different ways to do it. You can do it the way you're suggesting (though you don't use isset with CI's session class), but there are better ways. I'll tell you the way I do it, I'm sure someone else can offer other solutions.

I built an authorization library that tracked whether or not the user is logged in. I keep track of the data with sessions. In controllers that required the user be logged in, I can do something like this in the constructor.

if($this->auth->logged_in() && $this->auth->level > 5)
    //don't do anything, display the page as per the function
    //redirect to the login page

If you need more finely grained control, you could do this step in individual functions instead. If you wanted more broad control, you can put this functionality in a MY_ controller, and every controller that needd to be gaurded could inherit it.

Hope that helps.

How did you write the authorization library ?

The library class cannot recognize $this->session ?

Can someone help me with this ?

Also, how do i check if a user's logged in ?


doesnt work,

then will this do :


Or can you suggest something more robust ?????


I think what nelson.wells meant was that using the session class in CI to merely set the session would also set it in a cookie which could be changed by the user. Or so I'm thinking, he or others with more knowledge could clear that up.

If you want something quick, check out Ion Auth or Matt Auth in the Ignited Code forum on here.

Here's a posting I made in reference to another question on user auth. It's not definitive but might help.

Theme © iAndrew 2016 - Forum software by © MyBB