Page 1 of 1

Problems with Includes and Relative Paths

Posted: Wed Feb 06, 2008 1:06 pm
by cornrow
Hey guys,

I have a huge problem. I just spent 9 months building some software the relies on this one idea... and I just found a major problem.

My software includes files that are supplied by the user. It does this so that it can do some mysql magic and then display the page the user wanted.

So instead of showing index.php, they are redirected with htaccess to bounce.php which sets some database stuff and then includes index.php. To the user it's transparent and seems as if they have just gone to index.php as usual.

My problem is this : when bounce.php includes a file from a different directory (/blog for example), relative includes ('./wp-header.php') can't be included because './' is the web root directory rather than /blog.

Any ideas on this? Is there some way to change the directory php thinks it's in?

My best idea so far is to implement a caching system where upon first access files are scanned for relative includes, a duplicate is made with absolute includes, and the user is directed to the cached version until the checksum changes for the original. Kind of messy.

Tynan

Re: Problems with Includes and Relative Paths

Posted: Wed Feb 06, 2008 1:11 pm
by Christopher
There are many ways to solve this:

- you could use the include_path() function to add directories to search for files

- you could concat the absolute page to the file name like $Config['PATH'] . 'bounce.php';

- you could implement a function to do the file loading that internally knew the right thing to do

- you could create symbolic links to the directories you need in the 'blog' directory

- etc., etc., etc.