Welcome Guest, Not a member yet? Register   Sign In
stop logged in users accessing login page.
#1

[eluser]gazza7364[/eluser]
Hi

I'm trying to stop logged in user from accessing the login page and logged out users accesing pages without authentication.

I can stop users from accesing pages with the following code:=

Controller
Code:
function is_logged_out()
{
  $is_logged_out = $this->session->userdata('is_logged_in');
  if(!isset($is_logged_out) || $is_logged_out != true)
  {
   echo 'You don\'t have permission to access this page. <a href="http://localhost">Login</a>';
   die();  
  
  }  
}


but if I try the following to stop logged in users from accessing the login page.

Code:
function is_logged_in()
{
  $is_logged_in = $this->session->userdata('is_logged_in');
  if(isset($is_logged_in) || $is_logged_in = true)
  {
  echo 'You are already logged in please click the  link to take you back to your playlist. <a href="db/player">Playlist</a>';
   die();  
  
  }  
}

it sends to the first code thinking I,m logged out, when I'm logged in. which the puts it into a loop.

The session is started if the credentials are correct when logging in.
I'm not sure why the logged out version will work but not the logged in version.
I have tested the session to see if their is any, which comes back true.

The sesson is set with the following code

Code:
$ses = array(
    'username' => $this->input->post('username'),
    'is_logged_in' => true
   );
   $this->session->set_userdata($ses);
   $is_logged_in = $this->session->userdata($ses['is_logged_in']);

Any help will be appreciated,





Theme © iAndrew 2016 - Forum software by © MyBB