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

3

6

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?

Aboutface answered 15/4, 2014 at 14:47 Comment(9)
Did the web site itself work before you installed Codeigniter?Richburg
the only thing the website consists of is a login_form.php file that simply has a button and text fields in a form. This is very much a "hello world" style thing. The whole thing worked on a different computer yesterday (while working locally on that machine) but now that I've brought it to this machine, I'm having the 403 issue. The only thing I've changed was the name of the database, the username and password of the user. And I went and reflected those changes in the database.php file I posted above.Aboutface
whats the url you tried in your browser ?Siblee
localhost/intranet/CodeIgniter_2.1.4/application/views/welcome_message.phpAboutface
@user2662333 You need to use a URL to a controller, not the path to a view!Zonate
I tried the controller just now with this url: localhost/intranet/CodeIgniter_2.1.4/application/controllers/welcome.php but no luck. And @Rupam, I tried yours too but it just said "Not Found"Aboutface
This should work localhost/intranet/CodeIgniter_2.1.4/index.php/welcomeSiblee
That gets me the Codeigniter start page "Welcome to codeigniter..." but it doesn't find my welcome.php controller.Aboutface
you need to read up on basics please follow this (or any other) tutorial.Concessionaire
C
7

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
Conundrum answered 15/4, 2014 at 16:20 Comment(1)
not working...still Failed to load resource: the server responded with a status of 403 (Forbidden)Alastair
E
4

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

Elohim answered 4/11, 2019 at 9:28 Comment(0)
S
1

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.

Shebat answered 4/4, 2017 at 22:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.