How to Retrieve session id |
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(); } } ?>
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 )
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()
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;
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'; Hope you get it now... What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |