gpt4 book ai didi

php - 为什么我在本地使用 codeigniter 时会收到 403 Forbidden 错误?

转载 作者:可可西里 更新时间:2023-11-01 07:03:29 40 4
gpt4 key购买 nike

我是数据库工作的新手,我想知道是否有人可以帮助我理解为什么我只是在本地开发时不断收到 403 Forbidden 错误。我正在使用 codeigniter 来尝试创建一个简单的登录程序。前几天我让程序在另一台计算机上运行,​​但现在当我尝试在浏览器中打开“ View ”或“ Controller ”文件时,我在这台机器上得到的只是 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;

这是 Controller 文件 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!";
}
}
}

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

我在 MAMP 上的 phpMyAdmin 中创建了一个数据库,以具有代码指定的数据库和表,所以我很困惑为什么当我在浏览器中运行 welcome.php 文件时,我会收到 403 错误。它是本地的,所以应该没有问题吧?我一定是在某处遗漏了一个设置。有什么想法吗?

最佳答案

如评论中所述,您不应该尝试直接访问您的 Controller 所在的 .php 文件。不允许直接访问脚本,这就是您获得 403 的原因。您需要通过您的 index.php 发送请求。所以不要使用这个 URL

localhost/intranet/CodeIgniter_2.1.4/application/controllers/welcome.php

你需要使用

localhost/intranet/CodeIgniter_2.1.4/welcome //Use this if your .htaccess removes index.php
localhost/intranet/CodeIgniter_2.1.4/index.php/welcome

或访问您的登录表单

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

关于php - 为什么我在本地使用 codeigniter 时会收到 403 Forbidden 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23087195/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com