Forum Moderators: coopster

Message Too Old, No Replies

Can't do absolute path includes in PHP!

Absolute paths don't work in PHP

         

digitalmarker

9:10 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



Hi all,

I have spent 2 days on this already, tried every possible option to get it to work and have not been able to get it running.

I built my first PHP site using absolute paths for includes, and it works perfectly fine on my WinXP laptop with Apache.

However, once I moved it to the live server environment (Linux server running Apache), the includes no longer work.

The doc root is set properly (/www/webdev), however, I get an error every time it tries loading an include file with the following code:

<?php include("/topnav.php");?>

I got the following to work:

<?php include("/www/webdev/topnav.php");?>

as well as

<?php include("http://webdev/topnav.php");?>

However, I have had no luck getting the normal, clean absolute path reference to work.

Could someone please give me some ideas - I have very little time left, and don't want to recode the entire site with relative paths.

TIA

jatar_k

9:15 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



includes work via filesystem (unless you put http in there) so

/topnav.php

is looking in the server root, you would need to use

include $_SERVER['DOCUMENT_ROOT'] . '/topnav.php';

Philosopher

9:16 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try removing the "/" from your include and using simply

<?php include("topnav.php");?>

digitalmarker

9:34 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



Guys,

Both of these solutions are workarounds, and would require me to go through all of the pages on the site to update all include tags.

What's strange is that I placed these same files onto a different Linux server (my friends) and they worked perfectly off the bat with the absolute paths, without any configuration changes.

So, there must be some sort of a variable/setting on my server that is preventing it from functioning properly. What I need is at least an idea of where to look to find this setting and fix it that way.

Going through all the pages and replacing the include tags is the backup plan, which I am hoping to avoid.

Is tehre a way to add the $_SERVER['DOCUMENT_ROOT'] portion globally, so that I don't have to add it to every single include tag?

StupidScript

10:49 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps you could use
open_basedir
? Either set it in the server's php.ini (or php5.ini) file or in .htaccess on a per-directory basis.

open_basedir
"limits all file operations to the defined directory and below".

i.e.

open_basedir=/www/webdav/
to use
/topnav.php
as THAT root directory instead of the server's root or document root.

Also check the "Paths and Directories" section of php.ini to see if there's something useful to you in there.