Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting a 403 Forbidden error using codeigniter locally?

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?

like image 759
Rambo8000 Avatar asked Apr 15 '14 14:04

Rambo8000


People also ask

What does 403 Forbidden mean in IIS?

Microsoft IIS web servers provide more specific information about the cause of 403 Forbidden errors by suffixing a number after the 403, as in HTTP Error 403.14 - Forbidden, which means Directory listing denied. Check for URL errors and make sure you're specifying an actual web page file name and extension, not just a directory.

What is a 403 error and how to fix it?

Another reason for encountering a 403 error forbidden message is incorrect permissions for files or folders. In general, when files are created, they come with specific default file permissions, which control how you can read, write, and execute them.

What does 403 Forbidden mean on Lifewire?

He's been writing about tech for more than two decades and serves as the VP and General Manager of Lifewire. The 403 Forbidden error is an HTTP status code that means that accessing the page or resource you were trying to reach is absolutely forbidden for some reason.

How to make CodeIgniter index not show up in url?

CodeIgniter uses the Front-Conroller pattern, which means all requests are marshalled through a single controller, in this case index.php If you don't want that to show up in the URL, you need to setup up rewrites on your server. The CodeIgniter Wiki has a pretty comprehensive explanation.


1 Answers

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
like image 182
Pattle Avatar answered Nov 15 '22 07:11

Pattle