CodeIgniter Forums
Session library Issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: Session library Issue (/showthread.php?tid=62139)



Session library Issue - isabella - 06-12-2015

Hi guys,
I am developing a website but no idea why the session is not maintaining.When the user logged in the session is maintained but when I retrieve the data from session in another function it returns null while I check out in the logged in function session is maintaining there.

Here is both functions:


public function login(){
$this->load->model('admin_model');
$data['email'] = $this->input->post('email_a');
$data['password'] = md5($this->input->post('pw'));

$result = $this->admin_model->login($data);
//die(var_dump($result));
if($result==true){
echo "true";
$this->load->library('session');
$dataLogin=$this->session->set_userdata('loginData',$result['admin_id']);

// die(var_dump( $this->session->userdata('loginData')));
}


public function profile(){
$id= $this->session->userdata('loginData');
die(var_dump( $id));
}
Can anyone suggest any solution ?


RE: Session library Issue - Wouter60 - 06-13-2015

Include the session library in your config/autoload.php file:
PHP Code:
$autoload['libraries'] = array('database','session'); 
If you don't want that, make sure the session library is loaded by every method in your controller that needs it.


RE: Session library Issue - isabella - 06-13-2015

I already added this library in autoload file.Still its not working


RE: Session library Issue - Wouter60 - 06-13-2015

Which sess_driver do you use?
If you use the 'files' driver, you must setup a path where session variables are stored.
If you use the 'database' driver (which I did), you must add a specific table 'ci_sessions' to your database.
What are your 'session' settings in config.php?


RE: Session library Issue - Diederik - 06-14-2015

You should turn on php error reporting. I think it will tell give you a header has already been send error. Your line 'echo "true"' is causing this.

Please dont tell me you store thoses md5 hashed in your database? Your code suggests that at least. Its insecure... You should read up on this and atleast use sha as a hash function and store a salt with each record.


RE: Session library Issue - skunkbad - 06-14-2015

Unless you are just trying to learn, you should use one of the already made user authentication options for CodeIgniter. I have made Community Auth, but there is ion Auth, flexi auth, etc. There are hundreds of hours into the development of these solutions, and most assuredly safer than trying to develop your own.


RE: Session library Issue - isabella - 06-17-2015

Thanks guys for all the suggestions.I find the bug now it's fine.