Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Using Ion Auth to secure website section
#1

(This post was last modified: 11-13-2014, 10:18 PM by yhoiseth.)

Hi, everyone.

I'm trying to secure the entire members' area of a website using Ion Auth. I have managed blocking the default page (the index() function) in the following way:

PHP Code:
class Minside extends CI_Controller // Members' area to view orders, change user details and view public profile
{
    public function 
index() // Loads automatically
    
{
        if (!
$this->ion_auth->logged_in()) // Check to see if user is logged in
        
{
            echo 
'You are not logged in.'// TODO: Replace with login form
        
}
        else 
// If user is logged in
        
{
        
$data['title'] = 'Min side'// Set page title
        
$data['li1class'] = 'active'// Highlight menu item
        
$data['li2class'] = '';
        
$data['li3class'] = '';
        
$this->load->view('header'$data);
        
$this->load->view('minside'$data); // Members' area menu
        
$this->load->view('kjop_og_anmeldelser'); // Default page
        
$this->load->view('footer');
        }
    }
    
    public function 
offentlig_profil() // Public profile
    
{
        
$data['title'] = 'Offentlig profil';
        
$data['li1class'] = '';
        
$data['li2class'] = 'active';
        
$data['li3class'] = '';
        
        
$this->load->view('header'$data);
        
$this->load->view('minside'$data);
        
$this->load->view('offentlig_profil');
        
$this->load->view('footer');
    } 

If the user isn't logged in, they can't access example.com/minside. But they can still access example.com/minside/offentlig_profil.

How can i block access to the entire /minside website section without using the same if-statement in all the functions?
Reply
#2

Make a constructor and try this..

Code:
public function __construct() {
        parent::__construct();
        if (!$this->ion_auth->logged_in()) // Check to see if user is logged in
        {
            redirect('login/index');
        }
        
}
Reply
#3

That worked, tapan.thapa. Thanks a lot for your quick and helpful reply. I deeply appreciate the effort.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB