Welcome Guest, Not a member yet? Register   Sign In
Authentication checking
#3

[eluser]LuckyFella73[/eluser]
You could extend the CI_Controller with an Admin_Controller.
In your Admin_Controller construct you check for logged in
user. Then extend all controllers where access has to be restricted
with the Admin_Controller.

In application/core you would have:
Code:
// Admin_Controller.php

<?php

class Admin_Controller extends CI_Controller
{

function __construct()
{
  parent::__construct();
  
  // check for looged in user here
  // redirect if user is not logged
}
}

In your restricted controllers you would have:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Your_restricted_controller extends Admin_Controller {
function __construct()
{
  parent::__construct();
}
// more code here

I guess you need that in your config.php also:
Code:
// application/config/config.php

/*
| -------------------------------------------------------------------------
| Native spl_autoload_register() - by Kenneth Vogt
| -------------------------------------------------------------------------
|
| Here is an updated version of Phil Sturgeon’s code:
|
| Thanks to Phil Sturgeon and Kenneth Vogt.
|
| NOTE:
| Requires PHP 5.3.+
| As of CI 3.0 Dev - The constant EXT has been removed modified
| should work for all version of CI and PHP 5.3
|
| Place at the bottom of your ./application/config/config.php file.
| -------------------------------------------------------------------------
*/
spl_autoload_register(function($class)
{
if (strpos($class, 'CI_') !== 0)
{
  if (file_exists($file = APPPATH . 'core/' . $class . '.php'))
  {
   include $file;
  }
  elseif (file_exists($file = APPPATH . 'libraries/' . $class . '.php'))
  {
   include $file;
  }
}
});

Hope that makes sense to you


Messages In This Thread
Authentication checking - by El Forum - 06-22-2012, 08:26 AM
Authentication checking - by El Forum - 06-22-2012, 08:28 AM
Authentication checking - by El Forum - 06-22-2012, 08:39 AM
Authentication checking - by El Forum - 06-23-2012, 08:30 AM
Authentication checking - by El Forum - 06-25-2012, 01:40 AM
Authentication checking - by El Forum - 06-26-2012, 08:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB