Codeigniter: Store value of a dropdown into session variable

I have a dropdown in the login page which fetches company codes and it's respective ID as value. I need to store this particular value (ID) in a session variable so I may use it throughout site. So that when that particular company is selected I may be able to view the details of that particular company. If there is an alternate method for this, kindly let me know.


public function login ()
    $user = $this->get_by(array(
    'company_id' => $this->input->post('company_id'),
    'username' => $this->input->post('username'),
    'password' =>
), TRUE);

    if (count($user)) {
        // Log in user
        $data = array(
            'username' => $user->username,
            'id' => $user->id,
            'loggedin' => TRUE,
            'is_admin' => $user->is_admin,
            'company_id' => $user->company_id
        return TRUE;



    <td><select class="form-control" id="company_code"
name="company_code" required>
          <option value="0" selected>Select
          <?php foreach($locations as $location){
            $selected =
            echo "<option $selected
    <td><?php echo
form_input('username','','class="form-control" placeholder="Enter User
Name"'); ?></td>
    <td><?php echo
form_password('password','','class="form-control" placeholder="Enter
Password"'); ?></td>
    <td><?php echo form_submit('submit', 'Log in',
'class="btn btn-primary"'); ?></td>

I want the above company_id to be posted into a session variable so it maybe used throughout the program. Any help will be greatly appreciated.

Related to : Codeigniter: Store value of a dropdown into session variable

Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © All Rights Reserved .