Re[2]: [PHP] Document root, preferred way to find it???

2005-03-06 Thread Tom Rogers
Hi Leif,

Monday, March 7, 2005, 10:03:48 AM, you wrote:
LG Hello Tom,

LG Friday, March 4, 2005, 9:13:41 PM, you wrote:
TR This will set the include path just before the document root:

LG H. Not quite what I'm looking for. I set up some test folders and
LG files on a development machine to play with your script.

LG Here's how it was laid out:

LG The document root for the test site:
LG c:\sambar\docs\test

LG A subfolder of the doc root
LG folder1

LG A subfolder of the above folder1
LG folder2

LG Placing a file called test.php (containing your script) in all three
LG places (doc root, folder1, folder1/folder2) gives you the following
LG respectively. 

LG Root: c:\sambar\docs\test\test.php
LG Document root: c:\sambar\docs\test\test.php this is wrong
LG Base: test.php
LG Include: c:\cambar\docs\test\include
LG OS: winnt
LG Include: c:\cambar\docs\test\include;.;C:\php5\pear

Try running this one:

?php
if(isset($_SERVER[SCRIPT_FILENAME])){
$file_name = $_SERVER['SCRIPT_FILENAME'];
echo File name: $file_namebr;

$script = $_SERVER['SCRIPT_NAME'];
echo Script: $scriptbr;

$document_root = str_replace($script,'',$file_name);
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);
if(preg_match('/^win/i',$os))   $lk = ';';

ini_set(include_path,$include.$lk.$org_include);
echo Include: .ini_get(include_path).br;
}

and let me see what it prints

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Document root, preferred way to find it???

2005-03-06 Thread Tom Rogers
Hi,

Monday, March 7, 2005, 1:08:27 PM, you wrote:
LG Hello Tom,

LG Sunday, March 6, 2005, 6:18:54 PM, you wrote:
TR and let me see what it prints

LG Still not quite there.

LG Site root
LG **
LG File name: C:\Sambar\docs\test\test.php
LG Script: /test.php
LG Document root: C:\Sambar\docs\test\test.php
LG Base: test.php
LG Include: C:\Sambar\docs\test\include
LG OS: winnt
LG Include: C:\Sambar\docs\test\include;.;C:\php5\pear

LG **

LG Site root/folder1
LG ***
LG File name: C:\Sambar\docs\test\folder1\test.php
LG Script: /folder1/test.php
LG Document root: C:\Sambar\docs\test\folder1\test.php
LG Base: test.php
LG Include: C:\Sambar\docs\test\folder1\include
LG OS: winnt
LG Include: C:\Sambar\docs\test\folder1\include;.;C:\php5\pear

LG ***

LG Site root/folder1/folder2
LG ***
LG File name: C:\Sambar\docs\test\folder1\folder2\test.php
LG Script: /folder1/folder2/test.php
LG Document root: C:\Sambar\docs\test\folder1\folder2\test.php
LG Base: test.php
LG Include: C:\Sambar\docs\test\folder1\folder2\include
LG OS: winnt
LG Include:
LG C:\Sambar\docs\test\folder1\folder2\include;.;C:\php5\pear

LG ***

LG Thanks.

LG Cheers,
LG Leif Gregory 

LG -- 
LG TB Lists Moderator (and fellow registered end-user)
LG PCWize Editor  /  ICQ 216395  /  PGP Key ID 0x7CD4926F
LG Web Site http://www.PCWize.com


Ok I see where is is going wrong, try this:

?php
if(isset($_SERVER[SCRIPT_FILENAME])){
$file_name = str_replace('\\','/',$_SERVER['SCRIPT_FILENAME']);
echo File name: $file_namebr;

$script = str_replace('\\','/',$_SERVER['SCRIPT_NAME']);
echo Script: $scriptbr;

$document_root = str_replace($script,'',$file_name);
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);
if(preg_match('/^win/i',$os))   $lk = ';';

ini_set(include_path,$include.$lk.$org_include);
echo Include: .ini_get(include_path).br;
}

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Document root, preferred way to find it???

2005-03-04 Thread Tom Rogers
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);

Re[2]: [PHP] Document root, preferred way to find it???

2005-03-03 Thread Tom Rogers
Hi,

Thursday, March 3, 2005, 11:54:48 AM, you wrote:

A If I'm reading you correctly, then a truly transportable include might look 
like
A this:

A $doc_root= (isset($_SERVER['path_translated'])?
A $_SERVER['path_translated'] : 
A  $_SERVER['document_root'];


Exactly

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php