CodeIgniter Forums
How to Retrieve session id - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: How to Retrieve session id (/thread-70215.html)



How to Retrieve session id - Pankaj Kumar - 03-09-2018

login.php

<?php
class Login extends MY_Controller
{
public function index()
{
$this->load->view('login_view');
}
public function user_login()
{

$this->form_validation->set_error_delimiters('<p class="text-danger">','</p>');
if($this->form_validation->run('login_rules'))
{
$email = $this->input->post('uemail');
$password = $this->input->post('upassword');

$this->load->model('loginmodel');
$login_id = $this->loginmodel->login_valid($email, $password);
if($login_id)
{
$this->session->set_userdata('user_id', $login_id);

return redirect('admin/dashboard');

}

else
{
echo "password do not match.";
}
}
else
{
$this->load->view('login_view');
}

}
}

?>
----------------------------------------------------------------------------------------------------------------------------------------------------------
propertymodel.php
<?php 
class Propertymodel extends CI_Model
{
public function property_list()
{
$user_id = $this->session->userdata('user_id');
$query = $this->db
->select('prop_name')
->from('properties')
->where('user_id', $user_id )
->get();

return $query->result();
}
}

?>


RE: How to Retrieve session id - donpwinston - 03-09-2018

session_id() or $this->session->session_id


RE: How to Retrieve session id - InsiteFX - 03-09-2018

If you read the CodeIgniter Users Guide on Session Library you would have found your answer.


RE: How to Retrieve session id - Pankaj Kumar - 03-14-2018

(03-09-2018, 01:50 PM)InsiteFX Wrote: If you read the CodeIgniter Users Guide on Session Library you would have found your answer.

I read the user guide and implement same to same but I face the same problem.


RE: How to Retrieve session id - danielcr_2018 - 03-14-2018

You have to load session library. Add a __construct method to the Login controller and load the library. This will let you access to the library's functions in any method inside the controller. 

I use to get the session data in the controller instead of the model. Then I pass the necessary values to the model's function in the arguments, but that is a personal preference.

PHP Code:
public function __construct()
{
 
       parent::__construct();
 
       $this->load->library('session');
 
       ...




RE: How to Retrieve session id - Pankaj Kumar - 03-15-2018

Please check  the attachment  give me solutions....

please check config file session code:-
--------------------------------------------------------
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;


RE: How to Retrieve session id - InsiteFX - 03-15-2018

You need to set the sess_save_path

Create a folder named writable in ./application folder.

./application
-- writable

Then setup your sessions like below.

PHP Code:
$config['sess_driver'            'files';
$config['sess_cookie_name'       'ci_session';
$config['sess_expiration'        7200;
$config['sess_save_path'         APPPATH.'writable';
$config['sess_match_ip'          FALSE;
$config['sess_time_to_update'    300;
$config['sess_regenerate_destroy'] = FALSE

Hope you get it now...