php - CodeIgniter: no direct script access allowed
one text
Solution:
This is nothing to do with your .htaccess
file or the structure of the application folder. Each CodeIgniter file, except for the file initiating CodeIgniter, usually starts with the lines:
if (!defined('BASEPATH')) {
exit('No direct script access is allowed');
}
This stops unwanted users accessing your files.
In your case, because of the other framework, you are probably not initialising CodeIgniter properly. Normally BASEPATH
is defined in the public/index.php
file that starts CodeIgniter.
BASEPATH
is a reserved constant in CodeIgniter that defines where the CodeIgniter system is installed. The system folder is separate to the application folder as multiple applications can share the same CodeIgniter system, without having to install the framework each time.
It sound like you have to find a way to initialise CodeIgniter from within your other framework. Have a look at a getting started with CodeIgniter tutorial, specifically focusing on how to set up the main index.php
file.
Some background information:
You can see all the reserved constants here: https://codeigniter.com/userguide2/general/reserved_names.html
There is more chat about
if (!defined('BASEPATH'))
on the CodeIgniter forums: https://forum.codeigniter.com/post-348729.htmlindex.php
can be renamed but it will be in the a public folder and probably not in the application folder. It defines the location of the system folder, application folder, development environment etc. It then processes a variety of things before starting the framework withrequire_once BASEPATH . 'core/CodeIgniter.php';
as its last line of code. There is a lot of chat online about how to hideindex.php
in the URL, which makes finding other information about it difficult. This is where.htaccess
often gets mentioned in relation to CodeIgniter.