session_start();
function CheckAuthentication()
{
$admin = 1;
if($admin<>1) {
return false;
} else {
return true;
}
// WARNING : DO NOT simply return "true". By doing so, you are allowing
// "anyone" to upload and list the files in your server. You must implement
// some kind of session validation here. Even something very simple as...
// return isset($_SESSION['IsAuthorized']) && $_SESSION['IsAuthorized'];
// ... where $_SESSION['IsAuthorized'] is set to "true" as soon as the
// user logs in your system. To be able to use session variables don't
// forget to add session_start() at the top of this file.
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Logged_in
{
var $CI;
public function __construct()
{
$this->CI =& get_instance();
$this->CI->load->helper('url');
$this->CI->load->library('session');
if(!$this->CI->session->userdata('logged_in'))
redirect('login');
}
public function isAdmin()
{
//$statement
}
Controllers\test.php Code (PHP)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Captcha extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('Logged_in', 'auth');
//Statement อื่นๆ
//this->auth->isAdmin();
{