1
\$\begingroup\$

I haven't done much work with Code Igniter, and can't seem to get much of a definitive answer poking around as to what the best solution to this problem is. Before moving forward, I wanted to see if you had any suggestions.

The idea is that each user has access to about 30 specific 'sites', out of many (~1000). I will store an array in the session info, then when each site is about to be loaded, check to see if the site is in the array.

class Sessions extends CI_Controller{

  public function authenticate()
    {
        $this->load->model('User_model', '', true);

        if ($this->User_model->authenticate($this->input->post('username'), $this->input->post('password')))
        {
            $this->session->set_userdata('loggedin', true);
            $this->session->set_userdata('sites', $this->model->get_user_sites());

        }
        else
        {
            header('Location: /sessions/login/'.'1');
        }
    }

// http://domainname/protected_pages/serve_protected/24
class protected_pages extends MY_Controller{

     public function serve_protected ($site_id){
          if (in_array($this->session->unset_userdata('sites'), $site_id)||$this->session->unset_userdate('role')=='admin'){
               $this->load->view(page_view.php);
          }
     }

 }
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.