how to require_once in codeigniter

Posted on

how to require_once in codeigniter – Here in this article, we will share some of the most common and frequently asked about PHP problem in programming with detailed answers and code samples. There’s nothing quite so frustrating as being faced with PHP errors and being unable to figure out what is preventing your website from functioning as it should like php and codeigniter . If you have an existing PHP-based website or application that is experiencing performance issues, let’s get thinking about how to require_once in codeigniter.

I am trying to extend a library in codeigniter. The only way to do so seems to include the original library using require_once then load the extended library using $this->load->library()

right now I have tried

  1. require_once('ion_auth.php');
  2. require_once('home/SITE_NAME/public_html/FOLDER_NAME/application/libraries/ion_auth.php')
  3. require_once('/home/SITE_NAME/public_html/FOLDER_NAME/application/libraries/ion_auth.php')

but unfortunately not luck….. I keep getting this error

Message: require_once(...) [function.require-once]: failed to open stream: No such file or directory

Weird thing is though this works on my local xampp environment but not on the actual server.

Solution :

Use CodeIgniter’s built in constant, APPPATH


If the library is a codeigniter specific library, as sbaaaang points out, you should use:


However, if the library is just a generic PHP class or set of functions, the codeiginter loader may not recognize it. Then you will need to use either one of the generic loading operators (include, include_once, require, require_once), with the APPPATH constant, as also pointed out:


Do you know that Codeigniter has a loader class?

change this




and be sure your libraries/ion_auth.php file it's a class named `class ion_auth{}`