1

New at this, so apologies if I'm not using the correct terminology, but... Locally, in my scripts, I can include scripts using:

include('/include/sample.php');

And it will automatically traverse to my web directory for inclusion... However, when I upload it to my server, it uses the server root at "/".

I don't really know what to search for, otherwise, I'd google, it, but hoping someone knows what I need to change on the server?

  • You need to consider that an `include` statement uses file paths, not URLs. The root as the web server sees it is not the same as the file system root. In general it's a bad idea to use absolute paths in PHP, unless you do so using variables, as per Brett's answer. If nothing else, absolute paths break portability. – John Gardeniers Sep 17 '12 at 23:38

1 Answers1

1

Instead of modifying the php.ini you might consider modifying your include. You could use a relative path like:

include('include/sample.php');

or you could use an absolute path like:

include($_SERVER['DOCUMENT_ROOT'].'/include/sample.php');
Brett
  • 165
  • 1
  • 10