title: Codeigniter session not working with my code
body: <p>I have this problem with this session in codeigniter that nothing displays. I use to call the result with an ajax. If I direct it to echo only it shows the correct user id. I don't know were do I wrong? I hope someone will correct me. Thank you</p>
  
  <p>This is my function for user login. This is for setting a session for the current user login</p>
  
  <pre><code>public function login(){
  
      $username = $this-&gt;input-&gt;post('username');
      $password = $this-&gt;input-&gt;post('password');
  
          $sql= $this-&gt;crud-&gt;getData("
                  tbl_user","
                  user_username='$username' AND 
                  user_password=md5('$password')
                  LIMIT 1");
  
       if($sql['total']==1) { 
  
              $user_sess = array();
  
                   foreach($sql['rows'] as $row){
                       $user_sess = array('user_id'=&gt;$row-&gt;user_id,
                                         'user_name'=&gt;$row-&gt;user_username,
                                         'user_role'=&gt;$row-&gt;user_role,
                                         'profile_id'=&gt;$row-&gt;profile_id,
                                         'user_type'=&gt;$row-&gt;user_type,
                                         'user_status'=&gt;$row-&gt;user_status,
                                         'user_group_id'=&gt;$row-&gt;user_group_id,
                                         'user_sub_group_id'=&gt;$row-&gt;user_sub_group_id);
                   }            
  
              $this-&gt;session-&gt;set_userdata('user_sess', $user_sess); 
  
              $result['login']='valid';
         }else{
  
              $result['login']='invalid';
  
      }//end if else
  
      echo json_encode($result);
  
  }/*END LOGIN FUNCTION*/ 
  </code></pre>
  
  <p>This is the function were the session is not working. Calling current user login id</p>
  
  <pre><code>function user_current_details(){
  
  $user_id=$this-&gt;session-&gt;userdata('user_sess');
  
  
  $sql = $this-&gt;crud-&gt;getData("tbl_user as u,tbl_group as g, tbl_sub_group as sg, tbl_user_permission as up, tbl_user_profile as p", "u.user_id= '$user_id[user_id]' AND u.user_group_id=g.group_id AND u.user_sub_group_id = sg.sub_group_id AND up.user_user_perm ='$user_id[user_id]' AND u.profile_id=p.profile_id")['rows'];
  
  echo json_encode($sql);
  </code></pre>
  
  <p>}  </p>
  
  <p>And this is the Ajax function to display in the View. With this example I call the user profile picture to be display in the view.</p>
  
  <pre><code>function user_current_details(){
  
  $.post(baseurl + 'globalFunction/user_current_details', {
  
  }, function (data) {
      var result = eval('(' + data + ')');
      $("#img_user_current").attr('src',baseurl+'files/user_pics/'+result[0].profile_img);
  })}
  </code></pre>
  
  <p>Thank you. Sorry for my bad english</p>