Welcome Guest, Not a member yet? Register   Sign In
Please help Session
#1

[eluser]jonny tran[/eluser]
Welcome everyone
I have the code
controller:login
function index()
{
$this->session->unset_userdata('admin');

$this->load->view('login');
}

function go()
{
$usr = $this->input->post('username');
$pwd = $this->input->post('password');
$this->load->model('account_model');
$result = $this->account_model->login($usr, $pwd);
if ($result)
{
//$data = array('admin'=>$usr,
// 'id' => $result['userid']
// );
$user=$result['username'];
$id=$result['userid'];
$this->session->set_userdata('admin',$user);
$this->session->set_userdata('id',$id);
header("Location: ../dashboard");
}
else
{
$data = array('lgvalid'=>$this->lang->line('invalid_login'));
$this->session->set_userdata($data);
header("Location: ../login");
}

}
controller:dashboard
function Dashboard()
{
parent::Controller();
if(!$this->session->userdata('admin'))
header('Location: '.base_url().'login');
}

function index()
{
$message=''; $base_url = base_url();

/* Header */
$this->load->view('dashboard/dashboard_header', array('base_url' => $base_url));

/* Content */
$data = array('base_url' => $base_url,
'message' => $message);
$this->load->view('dashboard/dashboard_content', $data);

/* Footer */
$this->load->view('footer');
}
controller category:
function Category()
{
parent::Controller();
if(!$this->session->userdata('admin'))
header('Location: '.base_url().'login');
}
----------------------
successful login redirects
controller:dashboard

---
when I am in the controller dashboard switch to controller category lost session
please help.
thank you very much
#2

[eluser]pickupman[/eluser]
Welcome to the forums. You will find it easier when posting code to wrap the code using the code button shown in the editor.
On a sidenote rather than using header() just use:
Code:
redirect('login'); //Does the same as header('Location: ' .base_url(). 'login');

Nothing sticks out scanning over your code. Out of curiosity what happens when you view your cookies in your browser, do you still see the value set in the cookie?
#3

[eluser]jonny tran[/eluser]
but I have to sign a new 2 nd successful, do not understand why
#4

[eluser]Zeeshan Rasool[/eluser]
This issue is common in CI development and I faced many times. You should enable error reporting in index.php and always try to remove php warnings, bugs, errors so that this can be a big reason for session problem.
Also just create a Session.php file paste code I have attached with reply and put this file in application/libraries/

I downloaded this class from a site (not remembered sorry). This will hope fix your problem.
#5

[eluser]WanWizard[/eluser]
I don't see a reason why using your own session code would solve the problem.

The issue here is that (my guess) the TS uses cookies for session information, and not database sessions.

With cookies, when you redirect, no cookie update is send to the client. Therefore, you lose all session variable updates you have done in that same page request. You don't have that with database sessions (or any other session system that stores data server side), as updates will be stored immediately.




Theme © iAndrew 2016 - Forum software by © MyBB