0
私は登録ページにリダイレクトする登録フォームを持っています。今私は自分のページにログイン機能を追加したいと思うし、ログイン後に私のページにはそれぞれのユーザーのフォームが自動入力されるべきだ。しかし、私はそれを使用して助けてください方法を取得しませんでした。codeigniterで自分のプロジェクトにログイン機能を追加する
コントローラ
function login(){
$this->load->view('login_form.php');
}
function check_login(){
if($_POST) {
$result = $this->Student_info_model->validate_user($_POST);
if(!empty($result)) {
$data = ['id' => $result->user,'name' => $result->name ];
$this->session->set_userdata($data);
redirect('home');
} else {
$this->session->set_flashdata('flash_data', 'Username or password is wrong!');
redirect('Student_info/login');
}
}
モデル
public function validate_user($data) {
$this->load->database();
$this->db->where('name', $data['name']);
$this->db->where('password', md5($data['password']));
return $this->db->get('student_info_table')->row();
}
ビュー
<html>
<body>
<form action="<?php echo site_url('Student_info/check_login');?>"method="post">
<label for="username">Username</label>
<input type="text" name="username" /><br>
<label for="password">password</label>
<input type="text" name="password" /><br>
<input type="submit" value="login"/>
</form>