我刚开始使用 CI,我正在尝试登录。我已经阅读了一些教程,然后尝试自己制作一个,但它不起作用。当我尝试登录 ig 时出现错误:
在此服务器上找不到请求的 URL /Helptor/login_controller/going_in。
我尝试了很多东西,但没有任何效果。
这是我登录视图中的登录表单:
<form action="<?php echo base_url();?>login_controller/going_in" method="post" name="going_in">
<?php if(! is_null($msg)) echo $msg;?>
<table style="font-size: 30px;">
<tr>
<td>Username: </td>
<td><input type="text" size="45" name="username" style="background-color: #C5D2F5;"/></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" size="45" name="password" style="background-color: #C5D2F5;"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login" style="border-width: 2px; height: 40px; width: 120px; font-family: Calibri; font-size: 22px; background-color: #FEFEFF;"></td>
</tr>
<tr>
<td><a href="?lang=en"><img src="<?= base_url() ?>assets/img/United_Kingdom(Great_Britain).png"/></a>
<a href="?lang=nl"><img src="<?= base_url() ?>assets/img/Netherlands.png"/></a>
</td>
</tr>
</table>
登录控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class login_controller extends CI_Controller{
function __construct(){
parent::__construct();
}
public function index($msg = NULL){
$this->load->database();
$this->load->helper('url');
$data['msg'] = $msg;
$this->load->view('login', $data);
}
public function going_in(){
// Load the model
$this->load->model('login_model');
// Validate the user can login
$result = $this->login_model->validate();
// Now we verify the result
if(! $result){
// If user did not validate, then show them login page again
$msg = '<font color=red>Invalid username and/or password.</font><br />';
$this->index($msg);
}else{
// If user did validate,
// Send them to members area
redirect('user');
}
}
}
?>
登录模型:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login_model extends CI_Model{
function __construct(){
parent::__construct();
}
public function validate(){
// grab user input
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password'));
// Pre ping the query
$this->db->where('username', $username);
$this->db->where('password', $password);
// Run the query
$query = $this->db->get('users');
//check for results
if($query->num_rows == 1)
{
//create session data
$row = $query->row();
$data = array(
'id' => $row->ID,
'username' => $row->Username,
'level' => $row->Level,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
return false;
}
}
?>
基本网址:
$config['base_url'] = 'http://localhost/Helptor/';
索引页:
$config['index_page'] = '';
uri_protocol:
$config['uri_protocol'] = 'AUTO';
更新
我在地图应用程序中的 .htaccess 文件如下所示
拒绝一切
更新 2
这是我的文件夹结构:
localhost/helptor
-application
-controllers
-index.html
-login_controller.php
-user.php
-models
-login_model.php
-index.html
-views
-.htaccess
-index.html
-login.php
-user.php
.htaccess
index.html
-assets
-system
index.php