誰かが私が間違ったことをした(またはする必要がある)ことを教えてくれ、問題がルートファイルにあると思うかどうか疑問に思っています。ユーザーにログイン フォームが表示され、たとえば送信後にユーザー名が間違っている場合、URL は次のように表示されますhttp://localhost:8888/codeigniter/login/login_validation
。成功し、管理領域 (データベースからニュース記事をプルする) にログインすると、この URL は引き続き表示されます。http://localhost:8888/codeigniter/news.
ルートフォルダを調べて、「ワイルドカード」を使用しようとしましたが、失敗しました。参照用のコードは次のとおりです。その他の情報やファイルが必要な場合はお知らせください。ありがとう。
コントローラ:
class Login extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->load->view('login');
}
//Validate login area
public function login_validation() {
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback_username_check');
$this->form_validation->set_rules('password', 'Password', 'required|xss_clean|callback_password_check');
if($this->form_validation->run() == FALSE) {
//Field validation failed. User redirected to login page
$this->index();
}else{
$this->load->model('user_model');
$query = $this->user_model->login_details();
// if the user's credentials validated...
if($query) {
$data = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->session->set_userdata($data);
redirect('news');
}else{
$data['error'] ="Invalid Username or Password";
$this->load->view('login',$data);
}
}
}
function logout() {
$this->session->sess_destroy();
$this->index();
}
}
user_model.php の login_details 関数
function login_details() {
$this->db->where('username', $this->input->post('username'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get('login');
if($query->num_rows == 1){
return true;
}
}