Home » Php » php – Using require_once in Codeigniter

php – Using require_once in Codeigniter

Posted by: admin July 12, 2020 Leave a comment

Questions:

How do I use the require_once php function in Codeigniter on a normal PHP file? I’, currently getting an error.

Code:

require_once($_SERVER['DOCUMENT_ROOT'].'/php/jformer.php');

Error:

Message: require_once() [function.require-once]: http:// wrapper is disabled in the server configuration by allow_url_include=0

Message: require_once(http://localhost/site/php/jformer.php) [function.require-once]: failed to open stream: no suitable wrapper could be found

How to&Answers:

You don’t use $_SERVER['DOCUMENT_ROOT'] for this, you want to use APPPATH or BASEPATH instead, or just type the full path to the file. require_once should be passed a local file, not a URL.

Answer:

You should be using the path to the file and not the URL. Best (and certainly CI friendly) way would be to use BASEPATH or APPPATH constants.