Welcome Guest, Not a member yet? Register   Sign In
Redirection Problem
#1

[eluser]Don 007[/eluser]
Hi there, I am creating a login form, for admin section. What I have done here, I have created a controller restricted_area which serves as security for user. It is extend by other class in admin. Below is code for each controller class I am using.

CONTROLLER : restricted_area
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Restricted_area extends CI_Controller
{
function __construct($module_id = null)
{
parent::__construct();

if($this->session->userdata('user_id'))
{
redirect('administration');
}
else
{
redirect('administration/login');
}
}
}

CONTROLLER : Administration

<?php // admin class
require_once('restricted_area.php');
class Administration extends Restricted_area
{
function __construct()
{
parent::__construct();

}

function index()
{
$this->load->view('admin/dashboard');
}

function login()
{
$this->form_validation->set_rules('username','lang:login_username','callback_login_check');
$this->form_validation->set_error_delimiters('<div class="error">','</div>');

if($this->form_validation->run() == FALSE)
{
$this->load->view('admin/login');
}
else
{
redirect('administration');
}
}

function login_check($username)
{
$password = $this->input->post("password");
if(!$this->User->login($username,$password))
{
$this->form_validation->set_message('login_check',$this->lang->line('login_invalid_username_and_password'));
return false;
}
return true;
}

function logout()
{
$this->User->logout();
redirect('administration/login');
}
}

The basic logic to use restricted_area class is that when the user data is available
in session i.e. if he is logged in, he get redirected to dashboard, and if he is not logged in if he put url for dashboard he get redirected to login page.

when I am running this code, Mozilla display : This page cannot redirect properly, and Chrome display : This webpage has a redirect loop, too many redirects.

When I remove restricted_area class and run the administration class by extending CI_Controller, and write those codes in the functions, it works fine. But with this approach, I have to write the session user data check in every class or function for admin panel. Thats why I created a class restricted_area so that it get extended by all the class in admin panel so its session security get available to all. But redirection problem occurs.

Any suggestion..



#2

[eluser]Jason Stanley[/eluser]
You have 5 posts you should know that code should be surrounded in code tags by now..

It is obvious isn't it.. surely?

Code:
class Administration extends Restricted_area

Code:
redirect(‘administration’);

Code:
redirect(‘administration/login’);

Login form is in the restricted area..
#3

[eluser]Don 007[/eluser]
I am reposting the problem with in code tag.. please any suggestion.

I am creating a login form, for admin section. What I have done here, I have created a controller restricted_area which serves as security for user. It is extend by other class in admin. Below is code for each controller class I am using.

CONTROLLER : restricted_area
Code:
&lt;?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Restricted_area extends CI_Controller
{
function __construct($module_id = null)
{
  parent::__construct();

  if($this->session->userdata(‘user_id’))
  {
  redirect(‘administration’);
  }
  else
  {
  redirect(‘administration/login’);
  }
}
}

CONTROLLER : Administration


Code:
&lt;?php // admin class
require_once(‘restricted_area.php’);
class Administration extends Restricted_area
{
function __construct()
{
  parent::__construct();

}

function index()
{
  $this->load->view(‘admin/dashboard’);
}

function login()
{
  $this->form_validation->set_rules(‘username’,‘lang:login_username’,‘callback_login_check’);
  $this->form_validation->set_error_delimiters(’<div class=“error”>’,’</div>’);

  if($this->form_validation->run() == FALSE)
  {
  $this->load->view(‘admin/login’);
  }
  else
  {
  redirect(‘administration’);
  }
}

function login_check($username)
{
  $password = $this->input->post(“password”);
  if(!$this->User->login($username,$password))
  {
  $this->form_validation->set_message(‘login_check’,$this->lang->line(‘login_invalid_username_and_password’));
  return false;
  }
  return true;
}

function logout()
{
  $this->User->logout();
  redirect(‘administration/login’);
}
}

The basic logic to use restricted_area class is that when the user data is available
in session i.e. if he is logged in, he get redirected to dashboard, and if he is not logged in if he put url for dashboard he get redirected to login page.

when I am running this code, Mozilla display : This page cannot redirect properly, and Chrome display : This webpage has a redirect loop, too many redirects.

When I remove restricted_area class and run the administration class by extending CI_Controller, and write those codes in the functions, it works fine. But with this approach, I have to write the session user data check in every class or function for admin panel. Thats why I created a class restricted_area so that it get extended by all the class in admin panel so its session security get available to all. But redirection problem occurs.

Any suggestion..
#4

[eluser]Jason Stanley[/eluser]
I have already answered your question. Next time use the edit button instead of replying and reposting your thread...
#5

[eluser]InsiteFX[/eluser]
And if you look at your qoutes you will see what copy and paste does!




Theme © iAndrew 2016 - Forum software by © MyBB