Problems with Includes and Relative Paths

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cornrow
Forum Newbie
Posts: 3
Joined: Fri Sep 07, 2007 3:49 pm

Problems with Includes and Relative Paths

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Problems with Includes and Relative Paths

Post 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.
(#10850)
Post Reply