7

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!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
circey
  • 2,032
  • 6
  • 35
  • 51
  • Looks like you got bad advise with your last question. Use the different base URLs only for outputting HTML references. (Regarding that stylesheet issue, just use it in `` to compensate). – mario Nov 03 '11 at 04:06
  • Thanks mario. So I shouldn't even be using it for img paths? ie. `` – circey Nov 03 '11 at 04:12
  • A single base href will make images and stylesheets work. But only if you have relative paths. Otherwise you need the URL prefix everywhere. – mario Nov 03 '11 at 04:16

1 Answers1

4

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.

alex
  • 479,566
  • 201
  • 878
  • 984
  • 1
    Thanks Alex. I'm using `define` so I can use relative paths, so now I'm really confused. I posted [this question](http://stackoverflow.com/questions/7975313/using-root-relative-urls-and-problems-with-testing-locally) yesterday which resulted in my using `define`. I don't fully understand what you're saying but I'll... uhm... try something else perhaps? – circey Nov 03 '11 at 04:05