Bobby Z
Bobby Z

Reputation: 795

Catch session id in codeigniter

I wanna to know how to catch session id from device/client.

I have a Login API, the logic is like this. When client login to the apps they are also get an session id. the code is below:

public function user_post()
{
  $data = array (
    'username' => $this->input->get_post('username'),
    'password' => sha1($this->input->get_post('password'))
  );

  $result = $this->login_m->user_check($data);
  if ($result ) {
     foreach ($result as $row ) {

      $sess_array = array(
                  'username' => $row->username,
                  'email'    => $row->email,
                  'uniqueID' => $row->uniqueID,
                  'userid'   => $row->userid,
                  'session_id' => session_id()

                  );

      $this->session->set_userdata('logged', $sess_array);
      $this->response(array('success' => $this->session->userdata('logged') ));
    }
  } else {
    $this->response(array(404 => 'missing parameter'));
  }
}

it also has an array init. and the json response would like this below:

{
"success": {
"username": "johndoe123",
"email": "[email protected]",
"uniqueID": "1q2w3e4r5t6y",
"userid": "97",
"session_id": "1bbfdj07as68bvp3ctrboj8gs7"
}
}

the question is, how i to catch the session id that is store in client apps?

so, when they are trying to get some information like news, or their profile. The client apps send me back the session id.

I presume that session id has array data just like when they are try to login. so maybe i will get the array, array value will be the condition to get the news or profile.

CMIIW

Upvotes: 1

Views: 7194

Answers (2)

Try this

$this->session->userdata('session_id');

Upvotes: 0

Vivek Singh
Vivek Singh

Reputation: 2447

$session_data=$this->session->userdata('logged');

use this to get all the session data and you can get the particular data by iterating that array

like this $session_data['session_id']

Upvotes: 0

Related Questions