I have this on my controller named pages(i use it as a terminal to branch out to all views)
class pages extends MY_Controller {
public function verification(){
$session_data = $this->is_logged_in();
print_r($session_data);
if($this->is_logged_in()){
}
}
}
As you can see, i have a line 'print_r' on the session_data, i got some results the problem is it always returns only '1'.
This is the function on my base controller.
class MY_Controller extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function is_logged_in()
{
$user = $this->session->userdata();
return isset($user);
}
}
And this is the code block after logging in creating the session data on my authenticator controller.
Class user_authentication extends MY_Controller {
public function register(){
$this->form_validation->set_rules('username', 'Username','required|trim|min_length[8]|max_length[24]|is_unique[user.username]',
array('required' => 'You have not provided %s.','is_unique' => 'This %s already exists.'));
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[8]|max_length[16]');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|min_length[6]|max_length[30]|is_unique[user.email]',
array('required' => 'You have not provided %s. ','is_unique' => 'This %s already exists.'));
$this->form_validation->set_rules('type', 'Account Type', 'trim|required|min_length[1]|max_length[1]',
array('required' => 'please select: 1 - normal, 2 - trainer'));
$this->form_validation->set_error_delimiters('', '');
if ($this->form_validation->run() == FALSE){
$this->load->view('templates/header');
$this->load->view('templates/navigation');
$this->load->view('pages/login');
$this->load->view('templates/footer');
}else{
$data = array('username' => $this->input->post('username'),
'password' => $this->input->post('password'),
'email' => $this->input->post('email'),
'type' => $this->input->post('type'));
$result = $this->Account_model->create_account($data);
if($result == true){
$data['message_display'] = 'Registration Successful';
$this->load->view('templates/header');
$this->load->view('templates/navigation');
$this->load->view('pages/homepage',$data);
$this->load->view('templates/footer');
}else{
$data['message_display'] = 'Username and/or Email already exists';
$this->load->view('templates/header');
$this->load->view('templates/navigation');
$this->load->view('pages/login',$data);
$this->load->view('templates/footer');}
}
}
public function login(){
$this->form_validation->set_rules('username', 'Username', 'required|trim|min_length[8]|max_length[24]');
$this->form_validation->set_rules('password', 'Password', 'required|trim|min_length[8]|max_length[16]');
if($this->form_validation->run() == FALSE){
$this->load->view('templates/header');
$this->load->view('templates/navigation');
$this->load->view('pages/login');
$this->load->view('templates/footer');}
else{
$data = array('username' => $this->input->post('username'), 'password' => $this->input->post('password'));
$result = $this->Account_model->login_account($data);
$session_data = array('username' => $result['username'], 'email' => $result['email'], 'type' => $result['type']);
$this->session->set_userdata('isloggedin',$session_data);
$data['title'] = 'home';
$this->load->view('templates/header');
$this->load->view('templates/navigation');
$this->load->view('pages/home');
$this->load->view('templates/footer');}
}
There are some stuff that are basically useless as of right now but i'm putting them there for future uses. like the $data['title'] gonna use it as a placeholder for the title on the head of each view since i am using templates.
Am i doing something wrong? Why does when i print_r the session data from MY_Controller it only returns '1'.
I've been looking at guides but most of them are outdated and i am probably using deprecated stuff from past versions, if so kindly point them out, i want to practice coding neat and clean.