Hi,
Saturday, March 5, 2005, 5:47:07 AM, you wrote:
LG Hello Richard,
LG Friday, March 4, 2005, 11:41:29 AM, you wrote:
R http://php.net/set_include_path
LG Ok... Maybe I should put all this together in one e-mail so that all
LG the issues can be looked at...
LG The problem:
LG Finding a reliable method to include files, keeping in mind the
LG following:
LG 1. The site could be moved to a completely new host which could be of
LGa different OS, and/or web server software, and could either be the
LGone and only site on that host (dedicated server), or could be a
LGvirtual host (shared server).
LG 2. The site could remain on the same host but is required to move to a
LGnew path. i.e. from htdocs/mysite to htdocs/mynewsite
LG 3. The web host may or may not allow the use of .htaccess (Some Sambar
LGconfigurations for example).
LG 4. The method used would not affect any other virtual hosts. Meaning,
LGthe method used must be independent for each virtual host.
LG 5. The method used would not utilize a folder where other virtual
LGhosts could gain access to the included file (php.ini
LGinclude_path).
LG 6. The method (and this is the important one IMHO) would not require
LGediting x number of pages in a site to change some static path
LGthat was set on each page.
LG 7. The method used would not require a dedicated include file in
LGevery single folder of the site that could be included because it's
LGin the same folder as the page needing it, because those would all
LGhave to be edited to fix the path if condition 1 or 2 was met.
LG Previously proposed solutions:
LG 1. PHP.ini include_path
LGThis affects all virtual hosts and would require administrative
LGoverhead to prevent the owners of each virtual host from gaining
LGaccess to other virtual host's include files. I suppose you could
LGset it to something like: include_path=/php/includes and have a
LGseparate subfolder under that for each virtual host. But since that
LGfolder is outside the web folder, there would have to be some
LGmechanism (additional FTP account) for each person to gain access
LGto their own include folder to add/edit/delete files in that
LGfolder. Then if the site is moved and they aren't using an
LGinclude_path, you have to fix all your pages.
LG 2. set_include_path
LGThis means if your site moves, you must edit x number of pages in
LGthe site to correct the path.
LG 3. An include file in every directory to set the include path.
LGYou'd have to edit x number of these files to correct the path if
LGthe site moves. This would be much less work than the previous
LGitem, but it could be a lot of work on very big sites where you
LGdon't have shell accounts to do some scripted find/replace with.
LG 4. Use the full URL to the file in the include statement.
LGSee item 2.
LG 5. $_SERVER[DOCUMENT_ROOT] and $_SERVER['PATH_TRANSLATED']
LGNot always available or incorrect see
LGmid:[EMAIL PROTECTED]
LG I may have missed some things, and if I've misunderstood how something
LG should work, then please let me know. I'm just looking for a more or
LG less foolproof method which doesn't require fixing code if the site is
LG moved. The closest I can come to it is the function I wrote but is a
LG pain because you have to put it in every page where you need an
LG included file. Granted, you only have to do it once, and then you're
LG done and a site move wont affect it, but it's still kludgy if you ask
LG me.
LG ***
LG ?php
LG function dynRoot()
LG {
LG $levels = substr_count($_SERVER['PHP_SELF'],/);
LG for ($i=0; $i $levels - 1; $i++)
LG {
LG $relativeDir .= ../;
LG }
LG return $relativeDir;
LG }
?
LG ***
LG and then calling it as such:
LG include(dynRoot() . 'includes/db_connect.php');
LG I've had to move client sites between Sambar, Apache, IIS and Windows,
LG Linux. Most times I've had to go in and fix include paths because one
LG of the above solutions were originally used and wasn't viable on the
LG new host.
LG Thanks.
LG --
LG Leif (TB lists moderator and fellow end user).
LG Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
LG Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB
This will set the include path just before the document root:
if(isset($_SERVER[SCRIPT_FILENAME])){
$root = $_SERVER['SCRIPT_FILENAME'];
//echo Root: $rootbr;
$script = $_SERVER['SCRIPT_NAME'];
$document_root = str_replace($script,'',$root);
//echo Document root: $document_rootbr;
$base = basename($document_root);
//echo Base: $basebr;
$include = str_replace($base,'include',$document_root);
//echo Include: $includebr;
$os = strtolower(PHP_OS);
//echo OS: $osbr;
$lk = ':';
$org_include = ini_get(include_path);