[eluser]Jhourlad Estrella[/eluser]
I am using a table to handle my sessions. I currently creating the login module suing the following codes:
Code:
class Login extends Controller {
function Login()
{
parent::Controller();
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->library('session');
}
function index()
{
$data['attributes'] = array('class' => 'formbig', 'id' => 'frmLogin');
$data['f_username'] = null;
$data['f_password'] = null;
$data['errmsg'] = '';
$this->form_validation->set_rules('f_username', 'Username', 'required|alpha_numeric|xss_clean|min_length[3]|max_length[12]');
$this->form_validation->set_rules('f_password', 'Password', 'required|min_length[8]|max_length[30]');
if ($this->form_validation->run()) {
$uname = $this->input->post('f_username');
$passw = md5($this->input->post('f_password'));
if($user = dbGather('hib_users','*',"user_uname='$uname' AND user_passw='$passw'")) {
$this->session->set_userdata('username',$user[0]['user_uname']);
redirect('');
} else {
$data['errmsg'] = 'Invalid username/password.';
}
}
$this->load->view('header',$data);
$this->load->view('login/login_index',$data);
$this->load->view('footer',$data);
}
}
The view is somewhat like this:
Code:
<div class="hctr" style="width:220px; margin-top:10px; margin-bottom:10px; ">
<? if(validation_errors() OR $errmsg) { ?>
<div class="redbox">
<div>
<?=validation_errors()?>
<?=$errmsg?>
</div>
</div>
<br />
<? } ?>
<div class="graybox">
<?php
echo form_open('kblh-blogs-login',$attributes);
echo form_label('Your username','f_username');
echo form_input('f_username',$f_username);
echo form_label('Your password','f_password');
echo form_password('f_password',$f_password);
echo form_submit('btnSubmit','Login');
echo form_close();
?>
<div class="clr"></div>
</div>
</div>
Now, my problem is every time I load a page CI tries to create a new session, thereby erasing the USERDATA from the previous page.
For example:
1. Login.php loads.
5b56e2c6a787256a57a0c929b0af83bd 127.0.0.1 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv 1250365988
2. Login.php saves the USERDATA after successful authentication. Error - New sessiojn was created:
5b56e2c6a787256a57a0c929b0af83bd 127.0.0.1 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv 1250365988
29a25bed37c182bc70dbf975fef5f389 127.0.0.1 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv 1250365995 a:1:{s:8:"username";s:5:"admin";}
3. Redirects to home.php. Another error - new session created:
5b56e2c6a787256a57a0c929b0af83bd 127.0.0.1 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv 1250365988
29a25bed37c182bc70dbf975fef5f389 127.0.0.1 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv 1250365995 a:1:{s:8:"username";s:5:"admin";}
81e4e6bc2ad7dd63271edc71d13aa3d4 127.0.0.1 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv 1250365995
I have been using PHP for years and this is the first time I encountered this scenario. Can somebody please help me point out where am I doing it wrong?
Thanks guys!