Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a constant in require_once

I'm using the following to define root while in 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 a bit of a PHP beginner so please be gentle.

I'm trying to use 'URL' in 'require_once' and I can't seem to get it to work (as in the required file is not included). I've 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've checked http://www.php.net/manual/en/function.require-once.php and have searched on Stackoverflow and I'm not really making any headway at all.

I'm sure it's a really stupid and basic error I'm making here, but I'm at a loss and would really appreciate some help!

like image 552
circey Avatar asked Nov 03 '11 03:11

circey


1 Answers

The problem is probably because URL has a protocol, and it is trying to open the file over HTTP.

Including files remotely is disabled by default in PHP (allow_url_include), and for good reason.

You should be passing relative or absolute paths to files in your filesystem to be included.

like image 154
alex Avatar answered Sep 28 '22 11:09

alex