hairynuggets
hairynuggets

Reputation: 3311

Directories in codeigniter controller

I have two directories within my codeigniter controller.

/controllers/admin/

/controllers/members/

Because the directory folders are not themselves controllers I can't perform any functions if the user browses to the root of the directory.

Example if the user browses to

 /localhost/admin/

a view won't be loaded and will not show a 404. This lets users know that the directory does exist, giving me a security risk because people will know that I have an admin directory.

How is it possible to show a 404 message if the user browses to the root of the directory folder???

Upvotes: 0

Views: 375

Answers (2)

Mudshark
Mudshark

Reputation: 3253

You could add this in config/routes.php:

$route['admin'] = 'errors/page_missing';

$route['members'] = 'errors/page_missing';

... where Errors is a controller with a method of page_missing, where you load a 'file not found' view.

Upvotes: 1

Repox
Repox

Reputation: 15476

The way I do it is creating the default controller welcome.php in the directories I wan't to hide and add the show_404() function. Like this:

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

class Welcome extends CI_Controller {

    public function index()
    {
        show_404();
    }
}

This way, you don't have to fiddle with routes or rewrite rules. Simple and clean.

Upvotes: 1

Related Questions