Welcome Guest, Not a member yet? Register   Sign In
How to Retrieve session id
#1

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();
}
}

?>
Reply
#2

session_id() or $this->session->session_id
Simpler is always better
Reply
#3

If you read the CodeIgniter Users Guide on Session Library you would have found your answer.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(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.
Reply
#5

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');
 
       ...

Reply
#6

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;

Attached Files
.php   Admin.php (Size: 809 bytes / Downloads: 88)
.php   login.php (Size: 796 bytes / Downloads: 87)
.php   loginmodel.php (Size: 336 bytes / Downloads: 118)
.php   propertymodel.php (Size: 334 bytes / Downloads: 108)
.php   dashboard.php (Size: 1.26 KB / Downloads: 133)
Reply
#7

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...
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB