note 9379 added to include

From: Date: Mon, 30 Oct 2000 18:47:56 +0000
Subject: note 9379 added to include
Groups: php.notes 
Request: Send a blank email to php-notes+get-7187@lists.php.net to get a copy of this message
I had a problem with the "include". One of PHP's biggest problems is that if (as someone previously noted) if file A includes file B and file B wants to include file C and the files are in different directories there can be complications, because file B's include path automatically shifts to whatever file A's may be. A bit confusing to say the least. But there is hope! You can work around this problem by creating one page in every directory and sub-directory of your project. Name this file "path.php" in every directory. In path.php simply put: define("BASE", "path-to-root-project-directory"); then, at the top of every php page, before any other includes, include path.php. Then, before any include statements, use the BASE global. include "library.php" becomes: include BASE."library.php" Now you simply structure all includes to be relative to the project's base directory, and every page will know how to get there. This explanation makes it sound worse than it is. Hope this helps someone out there. http://www.php.net/manual/function.include.php

« previous php.notes (#7187) next »