CodeIgniter Forums

Full Version: OK - please, make me U N D E R S T A N D the login procedure!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Sven Delle[/eluser]
This is driving me totally nuts!

I STILL seem to have a huge problem understanding controllers and how to point the user to the right place.

Scenario:
I have an (so far) empty admin.php controller which extends an Admin_Controller.

The Admin_Controller - which look like this - checks if a user is logged in:

Code:
<?php
class Admin_Controller extends CI_Controller
{
public function __construct()
{
  parent::__construct();

  if(!$this->session->userdata('logged_in'))
  {
   $this->go_login();
  }
}

private function go_login()
{
  redirect('admin/admin_login');
}
}
/* End of file: ./application/modules/admin/controllers/admin.php */

This all works perfectly!

Well, that is - until next time you try to login (another browser window for some reason).

Then I simply CANNOT just redirect the already logged in user to the admin panel!

If I simply add an else statement like this:

Code:
if(!$this->session->userdata('logged_in'))
  {
   $this->go_login();
  }
  else
  {
   redirect('admin', 'location');
  }

The browser cannot 'redirect properly' it complains. Now, I know I'M the stupid one and somehow make myself end up in an endless loop. But I simply cannot get my head around this issue.

Could someone explain to me WHAT it is that I DONT'T GET?

NOTE: The reason for the Admin_Controller is that I plan on having a lot of other admin controllers in the end, and this is an easy way to protect them all.

El Forum

[eluser]InsiteFX[/eluser]
CodeIgniter Base Classes: Keeping it DRY

El Forum

[eluser]Sven Delle[/eluser]
Been there, done that etc ...

It's getting even worse. Suddenly - out of the blue - I cannot access my admin controller at all. I'm at the point where I've stripped ALL CODE FROM ALL FILES and all I have is:

ONE admin.php Controller containing absolutely nothing apart from the basics:

Code:
<?php
class Admin extends Admin_Controller {

public function __construct()
{
  parent::__construct();
}
}
/* End of file: ./application/modules/admin/controllers/admin.php */

I've even tried extending both MY_Controller (which is EMPTY and extends CI_Controller) AND CI_Controller. But ALL it gives med is a 404 page not found error.

Now, this HAS to a bug. Has ANYONE experienced anything like this before.

Everything was working the way it should. But SUDDENLY and YES S U D D E N L Y stopped working.

I've been on this for exactly 24 hours and 28 minutes now - and man I'm pissed off.


H E E E E E E E E L P!!! S O M E O N E!!!

El Forum

[eluser]Sven Delle[/eluser]
YES, I knew it.

As soon as I finished a near rant in the forums I saw that the index function was gone!?!?!?!?!?!!?!?!?!?

(Urge to swear) Christ all freakin' mighty! I'm officially AN IDIOT!

El Forum

[eluser]InsiteFX[/eluser]
Maybe your file system is corrupted try re-downloading and installing CodeIgniter.