How to set userid into a session array in codeigniter?
<p>I'm a bit new to Codeigniter, so I need some help, please if you can just post here the answer. Thank you.</p>

<p>Here is my <strong>Controller:</strong></p>

<pre><code>public function login()
{

    $this-&gt;load-&gt;library('form_validation');

    $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'required|valid_email|min_length[3]');
    $this-&gt;form_validation-&gt;set_rules('passwd', 'Passwd', 'required|min_length[3]');

    $data = array();

    if ($this-&gt;form_validation-&gt;run())
    {
        $email = $this-&gt;input-&gt;post('email');
        $passwd = $this-&gt;input-&gt;post('passwd');

        $this-&gt;load-&gt;model('user_model');

        if ($this-&gt;user_model-&gt;check($email, $passwd))
        {

            $this-&gt;session-&gt;set_userdata('user', $email);

            redirect(base_url('/'));
        }
        else
        {
            $data['error'] = 'Wrong e-mail or password.';
        }
    }

    $this-&gt;load-&gt;view('login', $data);
}
</code></pre>

<p>and here is my <strong>Model:</strong> </p>

<pre><code>public function __construct()
{
    // Call the CI_Model constructor
    parent::__construct();
}

public function check($email = NULL, $password = NULL)
{
    $this-&gt;db-&gt;select('id');
    $this-&gt;db-&gt;where('email', $email);
    $this-&gt;db-&gt;where('password', sha1($password));
    $this-&gt;db-&gt;limit(1);
    $result = $this-&gt;db-&gt;get('php_users_login');

    return ($result-&gt;num_rows() == 1);
}
</code></pre>

<p>I would like to put user-id into the session (database structure like id, email, password...)</p>

<p>Thank you for helping!</p>