首页 > 解决方案 > 为什么我无法进入登录页面?

问题描述

这是我在电脑上唯一能看到的地址http://localhost/onlineExam/login/validate_credentials

找不到对象!

在此服务器上找不到请求的 URL。引用页面上的链接似乎是错误的或过时的。请将该错误通知该页面的作者。

如果您认为这是服务器错误,请联系网站管理员。

错误 404

本地主机

Apache/2.4.39 (Win64) OpenSSL/1.1.1c PHP/7.3.7

class Login extends CI_Controller
{
    
    function index()
    {
        $data['main_content'] = 'login_form';
        $this->load->view('includes/templates', $data);
    }

    function validate_credentials(){
        $this->load->model('user_model');
        $query = $this->user_model->validate();

        if($query)// if the user's credentials validated...
        {
            $data = array(
                'username' => $this->input->post('username'), 'is_logged_in' => true

            );

            $this->session->set_userdata($data);
            redirect('site/users_area');
        }
        else{
            $this->index();
            $data['error'] = 'Invalid Username or Password';
            $data['main_content'] = 'login_form';
            $this->load->view('includes/templates', $data);
        }
    }

}

标签: codeigniter

解决方案


请检查根文件夹中是否存在 .htaccess 文件,即根据您的 URL 的“onlineExam”。如果不存在,请使用以下行创建/更新:

RewriteEngine On
RewriteBase /onlineExam/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

之后,还要检查 onlineExam/application/config/config.php 中的 base_url

$config['base_url'] = 'http://localhost/onlineExam';

推荐阅读