• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Session library Issue

#1
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

Reply

#2
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.
Reply

#3
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

Reply

#4
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?
Reply

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

#6
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.
Reply

#7
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

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.