CodeIgniter Forums
Codeigniter session issue. It logs me out from admin when I visit the un-admin part of the site! - 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: Codeigniter session issue. It logs me out from admin when I visit the un-admin part of the site! (/showthread.php?tid=59165)



Codeigniter session issue. It logs me out from admin when I visit the un-admin part of the site! - El Forum - 08-31-2013

[eluser]behnampmdg3[/eluser]
The admin is located in www.site.com/admin

The site is located in www.site.com/site

In admin I have a form and create a session to log in:
Login create session:
Code:
if($this->input->post('password')=='wws')
     {
      $newdata = array('logged_in' => TRUE);
      $this->session->set_userdata($newdata);
      redirect(base_url('index.php/edit'), 'refresh');
     }
Before edit, check if logged in:
Code:
if ($this->session->userdata('logged_in')!=TRUE)
    {
     redirect(base_url('index.php/log_in/check/'), 'refresh');      
    }
If I log in as admin, I can do all admin things. But if I refresh the page in main site, it logs me out from admin!!!!!!!!!!!!!!!



Why?????


Codeigniter session issue. It logs me out from admin when I visit the un-admin part of the site! - El Forum - 08-31-2013

[eluser]gummiforweb[/eluser]
When thing like this happen, what I'd do is, echo out the sessions to see what's the actual value is.
For example:

Code:
var_dump($this->session->all_userdata());
echo '<br/>';
var_dump($this->session->userdata('logged_in'));
echo '<br/>';
var_dump($this->session->userdata('logged_in')!=TRUE);
echo '<br/>';
die('=========');

if ($this->session->userdata('logged_in')!=TRUE)
{
redirect(base_url('index.php/log_in/check/'), 'refresh');      
}

try using the !== operator too.
if all_userdata() is an empty array, then there's some setting problem.