<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class VerifyLogin extends CI_Controller
{
public function __construct()
{
parent::__construct();
//Model for fetching users in database
$this->load->model('user', '', TRUE);
}
public function index()
{
//Load method to help verify form credentials
$this->load->library('form_validation');
//-----------------------------------------------
//Verify Existance of values in login form fields
//-----------------------------------------------
//Validate existance of username field value
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
//Validate existance of password field value, and if exists then call 'check_database' func
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
//If the form validation is false (i.e. Missing form fields)
if($this->form_validation->run() == FALSE){
//Redirect back to login page
$this->load->view('general-Login');
}
//Login Success, goto main-page
else{
//Go to main page
redirect('Main', 'refresh');
}
}
function check_database($password)
{
//Field validation succeeded. Validate against database
$username = $this->input->post('username');
//Check the username and password against database
$result = $this->user->login($username, $password);
//If there is a result
if($result){
//will be used for session information
$sess_array = array();
foreach ($result as $row){
$sess_array= array(
'id' => $row->id,
'username' => $row->username
);
//Session set as logged in
$this->session->set_userdata('logged_in', $sess_array);
}
return true;
}
//No existance of user or, incorrect password
else{
//Send Message of incorrect username or password
$this->form_validation->set_message('check_database', 'Invalid Username or Password');
return false;
}
}
}
したがって、ログインページからフォームデータを処理するverifyloginコントローラーがあります。データベースへのアクセスはうまく機能し、リダイレクト機能に到達するまではすべてが完全に機能します。更新してリダイレクトしようとすると、「未定義」というページが表示されます。「リフレッシュ」を削除してコントローラー名をそのままにしておくと、突然機能するようになりましたが、この「リフレッシュ」が機能しない理由を理解しようとしています。
を無効にしました、、 に.htaccess
設定しようと
しましたが、うまくいきませんでした。$config['uri_protocol']
REQUEST_URI
AUTO
PATH_INFO
また、フォーラムなどにオンラインで投稿するのはこれが初めてなので、お手柔らかにお願いします。