• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
About auth with CI session,when I close my browser,I need not login again

#1
[eluser]chmod[/eluser]
I wrote the code for my website auth.when I login,then close my browser,
then open the browser again, NO NEED for login agin,why?

but for security,I want to login again.

how to do it?

my code is like these:
-----------------------
class Login extends Controller{
function Login(){
parent::Controller();
}
function _check_username_password($username){
$this->load->model('center/login_model');
$login_result = $this->login_model->ilogin($username);
$password = $this->input->post('password');
$md5password = md5($password);

if ($login_result == $md5password){
return TRUE;
}else{
$this->validation->set_message('_check_username_password','username or password incorrect');
return FALSE;
}
}
function index(){
if ($this->session->userdata('islogin') === TRUE){
$data['title'] = "user center";
$this->load->view('center/mycenter_tpl',$data);
}else{
$username = $this->input->post('username');
$password = $this->input->post('password');

$rules['username'] = "trim|required|xss_clean|callback__check_username_password";
$rules['password'] = "trim|required|xss_clean";

$this->validation->set_rules($rules);
$fields['username'] = "username";
$fields['password'] = "password";
$this->validation->set_fields($fields);

if ($this->validation->run()){
$forward = $this->session->userdata('forward');
$islogin = array('username'=> $username,'islogin' => TRUE,'forward' => $forward);
$this->session->set_userdata($islogin);

if (isset($forward)){
redirect($forward,'refresh');
}else{
$data['title'] = "user center";
$this->load->view('center/mycenter_tpl',$data);
}
}else{
$data['title'] = "user login";
$this->load->view('center/login_tpl',$data);
}
}
}
}

#2
[eluser]Michael Wales[/eluser]
In config\config.php - you probably have this:
Code:
$config['sess_expiration']        = 0;

Which means the session will never expire. Some people have implemented a -1 value, for "expire when browser closes" - search around on the forums for it.

#3
[eluser]easymind[/eluser]
http://ellislab.com/forums/viewthread/79679/

#4
[eluser]chmod[/eluser]
thanks to your help.I resoved it.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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