0
私はcodeigniterプロジェクトに取り組んでいます。私は彼がクラスをロードするたびにユーザーのログインを確認するようにフックを作成したいと思います。 私のフックlocalhostがあなたをリダイレクトしました。 codeigniterフックで
$hook['post_controller_constructor'] = array(
'class' => 'Auth_login',
'function' => 'is_logged_in',
'filename' => 'Auth_login.php',
'filepath' => 'hooks',
);
また、設定ファイルでも有効になっています。
/**
* Auth_login
*/
class Auth_login
{
/**
* loading the CI instance
* @var [object]
*/
private $CI;
public function __construct()
{
$this->CI =& get_instance();
$this->CI->load->library('session');
$this->CI->load->helper('url');
}
/**
* Check the enduser for login verify, every time when the enduser
* loads the controller.
*/
public function is_logged_in()
{
/**
* if end user is not logged in, redirect to the login page
*/
if(!$this->CI->session->userdata('is_logged_in'))
{
$this->CI->session->set_tempdata('faliure','Please sign in to continue');
redirect(site_url('login/index'));
}
}
}
エンドユーザーのセッションログイン確認を確認します。ユーザーがログインしていない場合は、ログインページにリダイレクトします。ここ は、それがログインコントローラにリダイレクトする場合は、ローカルシステム上にあるもの 「localhostにリダイレクトされます何度も」 を作業するので、それは ようなエラーが表示さ
class Login extends CI_Controller {
// class constructor
// public function __construct() {
// parent::__construct();
// // load default
// $this->load->model('login_model');
// }
/**
* [display the login page, and verify the login page using "form_validation" for server side validation]
* @return [redirect] [description]
*/
public function index()
{
$this->load->model('login_model');
// on form sumbit
$on_sumbit = $this->input->post('verify');
if(isset($on_sumbit))
{
// server side validation for login
if ($this->form_validation->run('login/login_verify') == FALSE)
{
$this->load->view('login');
}
else
{
// get the form post value
$user_name = $this->input->post('user_name');
$password = $this->input->post('password');
// verify login
$verified = $this->login_model->login_verify($user_name,$password);
if($verified) // success
{
redirect('dashboard');
}
else // failure
{
$this->session->set_flashdata('login_failure','Please check your email and password and try again');
redirect('login/index');
}
}
}
// login page
$this->load->view('login');
}
// delete active session
public function logout()
{
$this->session->sess_destroy();
redirect('login');
}
}
をリダイレクトする私のコントローラでありますこの実際の問題。どんな助けもありがとう。
uは、このサンプル ような何かを試すことができます**リダイレクト( '/ index.phpを/ it_inventory/GET_USERS'、 'リフレッシュ'); **上記I –
を持っています第2引数として 'refresh'を追加しました。この問題が発生しているすべてのリダイレクトにこれを追加してください。 –
私もそれを試みました、それはページを再帰的にリフレッシュします。それはページをロードしていません..任意の他のソリューション..してください – Rakesh