为什么我在本地使用codeigniter获得403 Forbidden错误?

Ram*_*000 5 php mysql mamp codeigniter http-status-code-403

我是数据库工作的新手,我想知道是否有人可以帮助我理解为什么当我只是在本地开发时我一直得到403 Forbidden错误.我正在使用codeigniter尝试创建一个简单的登录程序.前几天我让程序在不同的计算机上运行,​​但是当我尝试在浏览器中打开"视图"或"控制器"文件时,现在我在这台计算机上的所有内容都是403错误.它必须在某处设置,但我根本不知道在哪里看.有任何想法吗?

这是我的database.php文件:

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'tester';
$db['default']['password'] = 'tester';
$db['default']['database'] = 'intranet';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Run Code Online (Sandbox Code Playgroud)

这是控制器文件welcome.php:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        $this->load->view('welcome_message');
    }

    public function login_form()
    {
        $this->load->view('login_form');
    }

    public function login_submit()
    {
        print_r( $_POST );
        $this->load->model('Usermodel', 'users');
        $match = $this->users->authenticate_user( $_POST['email'], $_POST['password'] );
        if( $match )
        {
            echo "User exists in database!";
        }
        else
        {
            echo "Email or password is wrong, bretheren!";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我添加了行$ autoload ['libraries'] = array('database');

我在MAMP上的phpMyAdmin中创建了一个数据库,以获得代码指定的数据库和表,所以我很困惑为什么当我在浏览器中运行welcome.php文件时,我收到403错误.它是本地的,所以甚至不应该有这个权利的问题?我一定错过了某个地方.有任何想法吗?

Pat*_*tle 6

如评论中所述,您不应该尝试直接访问.php控制器所在的文件.不允许直接脚本访问,这就是您获取403的原因.您需要通过您的index.php.所以而不是使用这个URL

localhost/intranet/CodeIgniter_2.1.4/application/controllers/welcome.php
Run Code Online (Sandbox Code Playgroud)

你需要使用

localhost/intranet/CodeIgniter_2.1.4/welcome //Use this if your .htaccess removes index.php
localhost/intranet/CodeIgniter_2.1.4/index.php/welcome
Run Code Online (Sandbox Code Playgroud)

或者访问您的登录表单

localhost/intranet/CodeIgniter_2.1.4/welcome/login_form //Use this if your .htaccess removes index.php
localhost/intranet/CodeIgniter_2.1.4/index.php/welcome/login_form
Run Code Online (Sandbox Code Playgroud)