Question

I'm new to Database work and I'm wondering if anyone can help me understand why I keep getting a 403 Forbidden error when I'm simply developing locally. I'm using codeigniter to try to create a simple login program. The other day I had the program working on a different computer but now all I get on this machine is 403 errors when I try to open the "view" or "controller" files in the browser. It must be some setting somewhere but I simply don't know where to look. Any ideas?

Here is my database.php file:

$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;

Here is the controller file 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!";
        }
    }
}

And I added the line $autoload['libraries'] = array('database');

I created a database in phpMyAdmin on MAMP to have the database and table as specified by the code so I'm confused why when I run the welcome.php file in the browser, I get a 403 error. It's local so there shouldn't even be a problem with that right? I must be missing a setting somewhere. Any ideas?

Was it helpful?

Solution

As mentioned in the comments you shouldn't be trying to directly access the .php file your controller resides in. Direct script access isn't allow which is why you are getting the 403. You need to send request through your index.php. So rather than using this URL

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

You need to use

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

Or to access your login form

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

OTHER TIPS

If there are htaccess files change denied to granted or just remove them entirely

This happened to me. And i couldn't solve it with above answers.

I tried to change the folder CodeIgniter-3.1.4 Access (Others) to Access files and now i can see the index.php file.

I haven't tried anything more. Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top