Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Can 'basedir' help me use root-relative paths in PHP includes?

Contributor ,
Jan 17, 2010 Jan 17, 2010

Copy link to clipboard

Copied

Hi,

<?php include ('/includes/_header.php'); ?>

...doesn't work, presumably because PHP believes the root directory to be "/home/user/domain/etc" instead of simply "domain"

I'm a bit new to PHP, but wouldn't the "basedir" attribute fix this? And if so, how would it be used in this context, so that Dreamweaver can continue to recognize where the files are located without a testing server needed, and root-relative paths can be used on the server itself?

Thanks!

TOPICS
Server side applications

Views

733
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2010 Jan 17, 2010

Copy link to clipboard

Copied

Try

<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/_header.php'); ?>

$_SERVER['DOCUMENT_ROOT'] is not supported by all servers (e.g. a Windows server running in CGI mode) but it's a useful first step. But try it and see.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 17, 2010 Jan 17, 2010

Copy link to clipboard

Copied

Thanks, but I specifically avoid $_SERVER['DOCUMENT_ROOT'] because Dreamweaver doesn't know what to do with it locally. It requires configuring a formal testing server, which I don't want to do.

Right now, I am editing my HTML/PHP files locally, then uploading those files to server. When editing locally with SPLIT or DESIGN view, DW does a good job of putting all the includes where they should go -- even when using root-relative paths -- but those root-relative paths result in "not found" errors once on the server (for reasons explained in the OP).

Document-relative paths (ie, "../../file.php") work on both the local machine AND the server. But I'd rather NOT use doc-relative paths if at all possible.

If "basedir" does what I suspect it does, then I think I may be able to have my cake (use root-relative paths) and eat it too (have those root-relative paths work on the server too).

Please let me know if I'm being in any way confusing.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2010 Jan 17, 2010

Copy link to clipboard

Copied

I'm afraid I don't know of any other way of using root relative links locally in PHP other than with $_SERVER['DOCUMENT_ROOT']

and a local testing server.

Any particular reason you're not using a local testing server?

There are other PHP experts on this forum who will know more.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 17, 2010 Jan 17, 2010

Copy link to clipboard

Copied

LATEST

mjyeager wrote:

I'm a bit new to PHP, but wouldn't the "basedir" attribute fix this?

No. PHP include commands require one of the following:

  • A fully qualified path
  • A document-relative path
  • A document located in the PHP include_path

Nothing else will work.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines