Using constants in require_once

I use the following to determine root during development:

define('LOCAL_URL', 'http://localhost/~xampp/Mysite'); define('REMOTE_URL', 'http://example.com'); define('DEV_VERSION', true); if(DEV_VERSION) define('URL', LOCAL_URL); else define('URL', REMOTE_URL); 

This concept is new to me, and I'm starting a little PHP, so please be careful.

I am trying to use the "URL" in "require_once", and I cannot get it to work (as it is not included in the required file). I tried the following:

 require_once URL.'/phpincludes/coming-events.php'; require_once(URL.'/phpincludes/coming-events.php'); require_once URL . '/phpincludes/coming-events.php'; require_once (URL . '/phpincludes/coming-events.php'); require_once(URL.'phpincludes/coming-events.php'); 

I checked http://www.php.net/manual/en/function.require-once.php and searched on Stackoverflow, and I did not achieve anything at all.

I am sure that this is really a stupid and basic mistake that I am making here, but I am at a loss and really appreciate some help!

+6
source share
1 answer

The problem is probably due to the fact that the URL has a protocol and is trying to open the file via HTTP.

File inclusion is remotely disabled by default in PHP ( allow_url_include ) and not without reason.

You must pass the relative or absolute file paths in your file system to be included.

+3
source

Source: https://habr.com/ru/post/900664/


All Articles