Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CodeIgniter - blocking direct access to files...

Featured Replies

Hi guys,

 

In codeigniter, is it necessary to block access to files (views, controllers etc.) you create using

 

define('VariableHere', TRUE);

 

and

 

if(!defined('VariableHere'){die('Direct access not permitted');}

 

(or .htaccess or similar etc etc.), or does CI automatically handle this?

 

Cheers!

 

Martin

Jock can you explain how you would do that? Would you just leave the index.php file in the web root?

 

Codeigniter has index.html files in the root of each folder, which stops indexes showing. But I use:

 

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

 

at the start of each file, it seems to do the trick. (It's what all codeigniter system files have as well)

 

Hope it helps

I'm no expert, I've only made one code igniter site, but I just put the system_folder outside of the web root. Then defined it in the index.php file as '../system'. This is standard practice with Zend Framework.

  • Author

Thanks Jock.

 

@asek - yeah, I looked at all the CI files and have started putting <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?> in the header of all my files.

 

As of CodeIgniter 2.0, the application directory is outside the system directory by default as well, so I guess it's best practice to put both outside htdocs.

 

M

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.