CodeIgniter Forums
About auth with CI session,when I close my browser,I need not login again - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: About auth with CI session,when I close my browser,I need not login again (/showthread.php?tid=8413)



About auth with CI session,when I close my browser,I need not login again - El Forum - 05-16-2008

[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);
}
}
}
}


About auth with CI session,when I close my browser,I need not login again - El Forum - 05-17-2008

[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.


About auth with CI session,when I close my browser,I need not login again - El Forum - 05-17-2008

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


About auth with CI session,when I close my browser,I need not login again - El Forum - 05-22-2008

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