Session library Issue |
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 ?
The FAS Solutions
corporate web development web designs and development services http://www.thefas-solutions.com
Include the session library in your config/autoload.php file:
PHP Code: $autoload['libraries'] = array('database','session');
I already added this library in autoload file.Still its not working
The FAS Solutions
corporate web development web designs and development services http://www.thefas-solutions.com
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?
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.
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.
Thanks guys for all the suggestions.I find the bug now it's fine.
The FAS Solutions
corporate web development web designs and development services http://www.thefas-solutions.com |
Welcome Guest, Not a member yet? Register Sign In |