Question

One other question – in the user controller login method, after checking pressed button (login or forget password), in line : $data = $this->user_model->login(); return correct user information; "user name, family, user id" to be used in dashboard for using in log table and heAder of pages how to send this data to dashboard? i tried to send it via redirect() but it fail

if ($this->form_validation->run() == TRUE) {
        if (!empty($_POST['login'])) {
            $data = $this->user_model->login();
            if ($data != NULL)
                {
             redirect('dashboard');                    
            } else {
                redirect('user/login', 'refresh');
       }
    } elseif (!empty($_POST['forget'])) {
        redirect('user/recover');
    }
}
$this->data['subview'] = 'users/login';
$this->load->view('users/_layout_modal', $this->data);
Was it helpful?

Solution

Function redirect() doesn't save anything. You can try save $data to session by writing $this->session->set_userdata('some_name', $data);

Then you can call them with $this->session->userdata('some_name');

Note that $data can be object or array.

Assume that $data is array, then in dashboard you can use something like this:

$data = $this->session->userdata('some_name');
echo 'Username: '.$data['username'].'<br />';
echo 'Family: '.$data['family'];

...... so on ........

OTHER TIPS

As per your question, you are validating the user login details and creating session for them.

Then store user information in session.

set session library auto-load in config/autoload.php. Then create session as below.

$this->session->set_userdata(
     array(
             "username"=>$username,
             "user_id" => $user_id,
             "family"  => $family    
            )    
);

In Dashboard:

You can access session with it's name:

echo $this->session->userdata("username");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top