会话用户数据出错

This is my Controller:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class admin extends ci_controller{


function __construct(){

    parent::__construct();

    $this->load->library('session');
    $this->load->helper(array('form', 'url', 'security', 'html'));
    $this->load->library('form_validation');
    $this->load->model($this->config->item('admin_model'), 'admin_db_connection', TRUE);
    //$this->load->model('admin_model' ,TRUE);
    //$this->load->helper('security');
    $this->load->helper('date');
    //$this->load->library('Ajax');
    $this->load->library("pagination");
    $this->load->database();
    $this->load->helper('url'); //You should autoload this one ;)
}



public function index(){
    $this->load->view('admin/login');
}


public function check_admin(){ //echo'admin';

    $this->load->helper('form');
    $this->form_validation->set_rules('admin_name','admin name','trim|required|xss_clean');
    $this->form_validation->set_rules('email','Email','trim|required|xss_clean');

    $this->form_validation->set_rules('password','password','trim|required|xss_clean');

    if($this->form_validation->run()== FALSE)
    { //echo 'invalid login ';
        $this->index();
    }
    else
    {
        $data=array();
        $data['admin_name']=$this->input->post('admin_name',true);
        $data['email']=$this->input->post('email',true);
        $data['password']=$this->input->post('password',true);
        //echo "<pre>";

        if ($query = $this->admin_db_connection->check_admin_validation($data))
        {
            // print_r($po);exit;
            $newdata=array
            (
             'id' => $query[0]['id'],
             'admin_name' => $query[0]['admin_name'],
             'email'=>$query[0]['email'],
             'status' => $query[0]['status'],
             'sign_in'=>TRUE
             );
            // echo "<pre>";
            //print_r($newdata);exit;

            $this->session->set_userdata('auth', $newdata);
            //$return= true;
            //print_r($auth);exit;
            redirect('dashboard');
            return TRUE;
        }
        else
        {
            echo 'invalid login';

            $this->index();
            //redirect('admin/index', 'refresh');
            return FALSE;
        }
    }
}

  function logout()
  {

    $this->session->sess_destroy();
    redirect('admin');
  }
}
?>

This is my model:

 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class admin_model extends ci_model{


function check_admin_validation($data){
    $this->session->userdata('auth');
    $this->db->select('*');
    $this->db->from('admin_user');
    $this->db->where('admin_name' , $data['admin_name']);
    $this->db->where('email', $data['email']);
    $this->db->where('password', $data['password']);
    $query=$this->db->get();
    if($query->num_rows()>0)
    {
        $resulet=$query->result_array();
        $query->free_result();
        return $resulet;
    }
    else        
    {
        return false;   
    }
  }
}
?>

When I use this code $this->session->set_userdata($newdata); instead of $this->session->set_userdata('auth', $newdata); then it works, but above code doesn't. Can someone tell me, where the problem is?

If I am not mistaken, the second parameter for the set_userdata function is a string, whereas you're passing an array.

This may be why your code isn't working.

The way to set session value at codeigniter is

$this->session->set_userdata('some_name', 'some_value');
//some_value should not be array
//But your are setting array as value which is wrong.

$this->session->set_userdata($newdata); 
//This will set each array key to your session.
//That's why it is working

If you really want to set array into one sesson key you can do it following way

   $this->session->set_userdata("auth",json_encode($newdata);

Now you can retrive data as

$auth=json_decode($this->session->userdata("auth"));

please look at codeigniter documentation

thank you now i solved my problem.thank you all and stackoverflow because if i not post here i cant find my answer.here is the problem my dashboard i passed wrong value 'sing_in' right value 'auth'.

 if (!$this->session->userdata('sing_in'))
          {  
              redirect('admin');
          }`enter code here`