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

2005-03-08 Thread Jochem Maas
Leif Gregory wrote:
Hello Marek,
Sunday, March 6, 2005, 7:08:24 PM, you wrote:
I don't see where that tells me where the include folder would be.
MK If you know how the files are layed out in your application, you do.
No... You missed the point of this whole thread which was explained in
point 1 and point 2 of the Problem section.
Restated in different words is how do you write some code which is
dynamic enough to withstand reorganization of folders either on the
same host, a different host (maybe with a different OS too), or a
mixture of any.
In HTML, a css declaration as follows:
link rel=stylesheet type=text/css title=Site CSS href=includes/site.css 
/
er does it really?
link rel=stylesheet type=text/css title=Site CSS href=includes/site.css 
/
I'm pretty sure the url is ./includes/site.css i.e. the include subdir of the
dir in which the html file that includes the link tag is in. if you move the
html file up or down a dir then the link to the css file will break
maybe browsers are smart enough to also check /includes/site.css
works regardless of where the page is, where it's moved to, and
regardless of how many folders down it is as long as there is indeed a
folder off the site root called includes and as long as there is a
file in that folder called site.css.
How do we mimic that capability in PHP so pages don't have to be
re-written if point 1 or point 2 of the Problem are met?
Cheers,
Leif Gregory 


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


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

2005-03-08 Thread Leif Gregory
Hello Jochem,

Tuesday, March 8, 2005, 3:30:19 AM, you wrote:
J link rel=stylesheet type=text/css title=Site CSS 
href=includes/site.css /

J I'm pretty sure the url is ./includes/site.css i.e. the include
J subdir of the dir in which the html file that includes the link tag
J is in. if you move the html file up or down a dir then the link to
J the css file will break

J maybe browsers are smart enough to also check /includes/site.css


Oops, my bad. I missed the slash in front. I've never run into a
problem using this:

link rel=stylesheet type=text/css title=Site CSS 
href=/includes/site.css /

and I've never placed a period at the beginning.


But you raise an interesting point. Is the server telling the browser
where the doc root is, or is the browser just guessing by dumping
everything after the domain name and using what's left as the doc
root. 



-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

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



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

2005-03-08 Thread Chris W. Parker
Leif Gregory mailto:[EMAIL PROTECTED]
on Tuesday, March 08, 2005 6:55 AM said:

 link rel=stylesheet type=text/css title=Site CSS
 href=/includes/site.css / 
 
 and I've never placed a period at the beginning.
 
 But you raise an interesting point. Is the server telling the browser
 where the doc root is, or is the browser just guessing by dumping
 everything after the domain name and using what's left as the doc
 root.

The browser is prepending the domain to the path of the css file.

It's the equivalent of:

http(s)://domain.com/includes/sites.css

The browser is looking for the file from the *WEB* root not the
filesystem root. (Forgive me if that is not the proper nomenclature.)
The browser is not doing anything special at all.



Chris.

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



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

2005-03-07 Thread Leif Gregory
Hello Tom,

Sunday, March 6, 2005, 11:20:04 PM, you wrote:
T I do this for security as I have things in include that I don't
T want to be avaiable directly to the browser Also you don't need a
T path for include files you can just do:

Don't necessarily disagree with you there other than if you place the
includes outside the web accessible folders how do you address the
managers of virtual hosts for the ability to modify, delete or add to
their particular include file? Additionally, how do you address
the naming convention of the include file.

i.e.
Site 'A' is using config.php
Site 'B' is using config.inc.php
Site 'C' wants to use config.php



T include('somefile.php');
T and it will be found regardless of where the script is located.

That's true enough..

BTW, good to see another TheBat! user here.

Thanks again.



-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

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



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

2005-03-07 Thread Tom Rogers
Hi,

Tuesday, March 8, 2005, 12:03:54 AM, you wrote:
LG Hello Tom,

LG Sunday, March 6, 2005, 11:20:04 PM, you wrote:
T I do this for security as I have things in include that I don't
T want to be avaiable directly to the browser Also you don't need a
T path for include files you can just do:

LG Don't necessarily disagree with you there other than if you place the
LG includes outside the web accessible folders how do you address the
LG managers of virtual hosts for the ability to modify, delete or add to
LG their particular include file? Additionally, how do you address
LG the naming convention of the include file.

LG i.e.
LG Site 'A' is using config.php
LG Site 'B' is using config.inc.php
LG Site 'C' wants to use config.php



T include('somefile.php');
T and it will be found regardless of where the script is located.

LG That's true enough..

LG BTW, good to see another TheBat! user here.

LG Thanks again.

I only do stuff for my own server which actually creates a couple
 of server variables called:

 SERVER[DOMAIN_ROOT] and SERVER[PHPINCDIR] which have the same
 values as the script we just cobbled together for each virtual
 domain.
 I don't suffer from the problem of lack of access to the
 include directory, So all my domains follow this layout:

/usr/local/apache/domains/domain1.com //root and chroot for ftp
 access
/usr/local/apache/domains/domain1.com/www web document root

/usr/local/apache/domains/domain1.com/include for all include files

If a hosting provider locks you in to the document root it's time to
change provider :)
As for naming convention I use .inc and stop apache from serving .inc
files.

-- 
regards,
Tom

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



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

2005-03-06 Thread Marek Kilimajer
dirname(__FILE__)
and then get rid of the subpath where the check is made ('/include' for 
example)

Leif Gregory wrote:
Hello Richard,
Friday, March 4, 2005, 11:41:29 AM, you wrote:
R http://php.net/set_include_path
Ok... Maybe I should put all this together in one e-mail so that all
the issues can be looked at...
The problem:
Finding a reliable method to include files, keeping in mind the
following:
1. The site could be moved to a completely new host which could be of
   a different OS, and/or web server software, and could either be the
   one and only site on that host (dedicated server), or could be a
   virtual host (shared server).
2. The site could remain on the same host but is required to move to a
   new path. i.e. from htdocs/mysite to htdocs/mynewsite
3. The web host may or may not allow the use of .htaccess (Some Sambar
   configurations for example).
4. The method used would not affect any other virtual hosts. Meaning,
   the method used must be independent for each virtual host.
5. The method used would not utilize a folder where other virtual
   hosts could gain access to the included file (php.ini
   include_path).
6. The method (and this is the important one IMHO) would not require
   editing x number of pages in a site to change some static path
   that was set on each page.
7. The method used would not require a dedicated include file in
   every single folder of the site that could be included because it's
   in the same folder as the page needing it, because those would all
   have to be edited to fix the path if condition 1 or 2 was met.
Previously proposed solutions:
1. PHP.ini include_path
   This affects all virtual hosts and would require administrative
   overhead to prevent the owners of each virtual host from gaining
   access to other virtual host's include files. I suppose you could
   set it to something like: include_path=/php/includes and have a
   separate subfolder under that for each virtual host. But since that
   folder is outside the web folder, there would have to be some
   mechanism (additional FTP account) for each person to gain access
   to their own include folder to add/edit/delete files in that
   folder. Then if the site is moved and they aren't using an
   include_path, you have to fix all your pages.
2. set_include_path
   This means if your site moves, you must edit x number of pages in
   the site to correct the path.
3. An include file in every directory to set the include path.
   You'd have to edit x number of these files to correct the path if
   the site moves. This would be much less work than the previous
   item, but it could be a lot of work on very big sites where you
   don't have shell accounts to do some scripted find/replace with.
4. Use the full URL to the file in the include statement.
   See item 2.
5. $_SERVER[DOCUMENT_ROOT] and $_SERVER['PATH_TRANSLATED']
   Not always available or incorrect see
   mid:[EMAIL PROTECTED]
I may have missed some things, and if I've misunderstood how something
should work, then please let me know. I'm just looking for a more or
less foolproof method which doesn't require fixing code if the site is
moved. The closest I can come to it is the function I wrote but is a
pain because you have to put it in every page where you need an
included file. Granted, you only have to do it once, and then you're
done and a site move wont affect it, but it's still kludgy if you ask
me.
***
?php
function dynRoot() 
{ 
  $levels = substr_count($_SERVER['PHP_SELF'],/); 

  for ($i=0; $i  $levels - 1; $i++) 
  { 
$relativeDir .= ../; 
  } 

  return $relativeDir; 
}
?
***

and then calling it as such:
include(dynRoot() . 'includes/db_connect.php');
I've had to move client sites between Sambar, Apache, IIS and Windows,
Linux. Most times I've had to go in and fix include paths because one
of the above solutions were originally used and wasn't viable on the
new host.
Thanks.
   

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


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

2005-03-06 Thread Leif Gregory
Hello Tom,

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

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

Here's how it was laid out:

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

A subfolder of the doc root
folder1

A subfolder of the above folder1
folder2

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

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

Ultimately, this would be the correct folder I would want, but see the
below two tests.

Root: c:\sambar\docs\test\folder1\test.php
Document root: c:\sambar\docs\test\folder1\test.php
Base: test.php
Include: c:\sambar\docs\test\folder1\include
OS: winnt
Include: c:\sambar\docs\test\folder1\include;.;C:\php5\pear

Root: c:\sambar\docs\test\folder1\folder2\test.php
Document root: c:\sambar\docs\test\folder1\folder2\test.php
Base: test.php
Include: c:\sambar\docs\test\folder1\folder2\include
OS: winnt
Include: c:\sambar\docs\test\folder1\folder2\include;.;C:\php5\pear


I don't see where your script is giving me the include folder I want.

Thanks though.

Cheers,
Leif Gregory 

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

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



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

2005-03-06 Thread Leif Gregory
Hello Marek,

Sunday, March 6, 2005, 4:23:51 PM, you wrote:
MK dirname(__FILE__)

MK and then get rid of the subpath where the check is made
MK ('/include' for example)


I'm not sure I'm completely following you. Let's say I had the
following:

Site root
c:\apache\htdocs\test

A subfolder of site root
folder1

A subfolder of the above folder1
folder2

If I call dirname(__FILE__) from a page in each folder I'll get the
following respectively:

c:\apache\htdocs\test
c:\apache\htdocs\test\folder1
c:\apache\htdocs\test\folder1\folder2

I don't see where that tells me where the include folder would be.


Cheers,
Leif Gregory 

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

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



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

2005-03-06 Thread Marek Kilimajer
Leif Gregory wrote:
I'm not sure I'm completely following you. Let's say I had the
following:
Site root
c:\apache\htdocs\test
A subfolder of site root
folder1
A subfolder of the above folder1
folder2
If I call dirname(__FILE__) from a page in each folder I'll get the
following respectively:
c:\apache\htdocs\test
c:\apache\htdocs\test\folder1
c:\apache\htdocs\test\folder1\folder2
I don't see where that tells me where the include folder would be.
If you know how the files are layed out in your application, you do.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


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

2005-03-06 Thread Leif Gregory
Hello Marek,

Sunday, March 6, 2005, 7:08:24 PM, you wrote:
 I don't see where that tells me where the include folder would be.
MK If you know how the files are layed out in your application, you do.

No... You missed the point of this whole thread which was explained in
point 1 and point 2 of the Problem section.

Restated in different words is how do you write some code which is
dynamic enough to withstand reorganization of folders either on the
same host, a different host (maybe with a different OS too), or a
mixture of any.

In HTML, a css declaration as follows:
link rel=stylesheet type=text/css title=Site CSS 
href=includes/site.css /

works regardless of where the page is, where it's moved to, and
regardless of how many folders down it is as long as there is indeed a
folder off the site root called includes and as long as there is a
file in that folder called site.css.

How do we mimic that capability in PHP so pages don't have to be
re-written if point 1 or point 2 of the Problem are met?


Cheers,
Leif Gregory 

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

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



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

2005-03-06 Thread Leif Gregory
Hello Tom,

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

Still not quite there.

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

**

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

***

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

***

Thanks.

Cheers,
Leif Gregory 

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

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



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

2005-03-06 Thread Leif Gregory
Hello Tom,

Sunday, March 6, 2005, 10:00:17 PM, you wrote:
TR Ok I see where is is going wrong, try this:

Oh, very close. Although you have it at $document_root and all
that needs to be added is '/include' like below:

$include = $document_root . '/include';

Otherwise it's one directory too far up because you're replacing the
site root 'test' (in this case) with 'include'.

We wanted: 'C:/Sambar/docs/test/include'

Here's from your script.

Site root:
**

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

**

Site root/folder1
**

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

**

Site root/folder1/folder2
**

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

**



After my change:

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

The other two folders moving back up the tree are the same result.

So the final looks like:


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);
$include = $document_root . '/include';
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;
}



It's a great effort and looks bulletproof. Can you shoot any holes in
mine? A full explanation at:
http://www.devtek.org/tutorials/dynamic_document_root.php

I only throw mine back out there because it's shorter. I think it's
solid, but only because I haven't broken it yet. :-)

Both our solutions suffer the same problem. They have to be on every
page that requires an include, because we can't rely on a new host
having our code in their auto_prepend file

**

function dynRoot()
{
  $levels = substr_count($_SERVER['PHP_SELF'],/);

  for ($i=0; $i  $levels - 1; $i++)
  {
$relativeDir .= ../;
  }

  return $relativeDir;
}

include(dynRoot() . 'includes/somefile.php')

**

Thanks again!


Cheers,
Leif Gregory 

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

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



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

2005-03-06 Thread Tom Rogers
Hi,

Monday, March 7, 2005, 3:57:50 PM, you wrote:
LG Hello Tom,

LG Sunday, March 6, 2005, 10:00:17 PM, you wrote:
TR Ok I see where is is going wrong, try this:

LG Oh, very close. Although you have it at $document_root and all
LG that needs to be added is '/include' like below:

LG $include = $document_root . '/include';

LG Otherwise it's one directory too far up because you're replacing the
LG site root 'test' (in this case) with 'include'.

LG We wanted: 'C:/Sambar/docs/test/include'

LG Here's from your script.

LG Site root:
LG **

LG File name: C:/Sambar/docs/test/test.php
LG Script: /test.php
LG Document root: C:/Sambar/docs/test
LG Base: test
LG Include: C:/Sambar/docs/include
LG OS: winnt
LG Include: C:/Sambar/docs/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
LG Base: test
LG Include: C:/Sambar/docs/include
LG OS: winnt
LG Include: C:/Sambar/docs/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
LG Base: test
LG Include: C:/Sambar/docs/include
LG OS: winnt
LG Include: C:/Sambar/docs/include;.;C:\php5\pear

LG **



LG After my change:

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

LG The other two folders moving back up the tree are the same result.

LG So the final looks like:
LG 

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

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

LG $document_root = str_replace($script,'',$file_name);
LG echo Document root: $document_rootbr;

LG $base = basename($document_root);
LG echo Base: $basebr;

LG //$include = str_replace($base,'include',$document_root);
LG $include = $document_root . '/include';
LG echo Include: $includebr;

LG $os = strtolower(PHP_OS);
LG echo OS: $osbr;

LG $lk = ':';
LG $org_include = ini_get(include_path);
LG if(preg_match('/^win/i',$os))   $lk = ';';

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

LG 

LG It's a great effort and looks bulletproof. Can you shoot any holes in
LG mine? A full explanation at:
LG http://www.devtek.org/tutorials/dynamic_document_root.php

LG I only throw mine back out there because it's shorter. I think it's
LG solid, but only because I haven't broken it yet. :-)

LG Both our solutions suffer the same problem. They have to be on every
LG page that requires an include, because we can't rely on a new host
LG having our code in their auto_prepend file

LG **

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 include(dynRoot() . 'includes/somefile.php')

LG **

LG Thanks again!


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

I do this for security as I have things in include that I don't want
to be avaiable directly to the browser Also you don't need a path for include
files you can just do:

include('somefile.php');

and it will be found regardless of where the script is located.


-- 
regards,
Tom

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



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

2005-03-04 Thread Chris W. Parker
Leif Gregory mailto:[EMAIL PROTECTED]
on Thursday, March 03, 2005 5:31 PM said:

 Hello Richard,
 
 Thursday, March 3, 2005, 1:15:38 PM, you wrote:
 include_path
 
 In the php.ini? But wouldn't that affect every virtual host on the
 server? Meaning I'd have to put all the includes for every virtual
 host in the same place?

.htaccess




Chris.

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



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

2005-03-04 Thread Leif Gregory
Hello Chris,

Friday, March 4, 2005, 9:58:05 AM, you wrote:
C .htaccess

Right.. But if you're on a hosted server running Sambar which is
configured to ignore .htaccess, then what? (I'm not being facetious,
this is actually an issue I've run across for a client).

My point I guess, is that there should be a simple way in PHP to
reliably pull the DOC_ROOT for a virtual host that doesn't require
fixing x number of pages if you move the site to another server or
to another folder. PHP is great in terms of portability, but this
seems to be a major sticking point in making it less portable.

A webserver always knows where it is (i.e. external CSS declarations).


-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

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



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

2005-03-04 Thread Richard Lynch




Chris W. Parker wrote:
 Leif Gregory mailto:[EMAIL PROTECTED]
 on Thursday, March 03, 2005 5:31 PM said:

 Hello Richard,

 Thursday, March 3, 2005, 1:15:38 PM, you wrote:
 include_path

 In the php.ini? But wouldn't that affect every virtual host on the
 server? Meaning I'd have to put all the includes for every virtual
 host in the same place?

 .htaccess

http://php.net/set_include_path

-- 
Like Music?
http://l-i-e.com/artists.htm

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



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

2005-03-04 Thread Leif Gregory
Hello Richard,

Friday, March 4, 2005, 11:41:29 AM, you wrote:
R http://php.net/set_include_path


Ok... Maybe I should put all this together in one e-mail so that all
the issues can be looked at...

The problem:

Finding a reliable method to include files, keeping in mind the
following:

1. The site could be moved to a completely new host which could be of
   a different OS, and/or web server software, and could either be the
   one and only site on that host (dedicated server), or could be a
   virtual host (shared server).

2. The site could remain on the same host but is required to move to a
   new path. i.e. from htdocs/mysite to htdocs/mynewsite

3. The web host may or may not allow the use of .htaccess (Some Sambar
   configurations for example).

4. The method used would not affect any other virtual hosts. Meaning,
   the method used must be independent for each virtual host.

5. The method used would not utilize a folder where other virtual
   hosts could gain access to the included file (php.ini
   include_path).

6. The method (and this is the important one IMHO) would not require
   editing x number of pages in a site to change some static path
   that was set on each page.

7. The method used would not require a dedicated include file in
   every single folder of the site that could be included because it's
   in the same folder as the page needing it, because those would all
   have to be edited to fix the path if condition 1 or 2 was met.


Previously proposed solutions:

1. PHP.ini include_path
   This affects all virtual hosts and would require administrative
   overhead to prevent the owners of each virtual host from gaining
   access to other virtual host's include files. I suppose you could
   set it to something like: include_path=/php/includes and have a
   separate subfolder under that for each virtual host. But since that
   folder is outside the web folder, there would have to be some
   mechanism (additional FTP account) for each person to gain access
   to their own include folder to add/edit/delete files in that
   folder. Then if the site is moved and they aren't using an
   include_path, you have to fix all your pages.

2. set_include_path
   This means if your site moves, you must edit x number of pages in
   the site to correct the path.

3. An include file in every directory to set the include path.
   You'd have to edit x number of these files to correct the path if
   the site moves. This would be much less work than the previous
   item, but it could be a lot of work on very big sites where you
   don't have shell accounts to do some scripted find/replace with.

4. Use the full URL to the file in the include statement.
   See item 2.

5. $_SERVER[DOCUMENT_ROOT] and $_SERVER['PATH_TRANSLATED']
   Not always available or incorrect see
   mid:[EMAIL PROTECTED]


I may have missed some things, and if I've misunderstood how something
should work, then please let me know. I'm just looking for a more or
less foolproof method which doesn't require fixing code if the site is
moved. The closest I can come to it is the function I wrote but is a
pain because you have to put it in every page where you need an
included file. Granted, you only have to do it once, and then you're
done and a site move wont affect it, but it's still kludgy if you ask
me.

***
?php
function dynRoot() 
{ 
  $levels = substr_count($_SERVER['PHP_SELF'],/); 

  for ($i=0; $i  $levels - 1; $i++) 
  { 
$relativeDir .= ../; 
  } 

  return $relativeDir; 
}
?
***

and then calling it as such:

include(dynRoot() . 'includes/db_connect.php');


I've had to move client sites between Sambar, Apache, IIS and Windows,
Linux. Most times I've had to go in and fix include paths because one
of the above solutions were originally used and wasn't viable on the
new host.

Thanks.
   

-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

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



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

2005-03-04 Thread Richard Lynch
 6. The method (and this is the important one IMHO) would not require
editing x number of pages in a site to change some static path
that was set on each page.

I believe you could get x to be 1, if you do this:

1. Set up a config_include_path.inc file in your DocumentRoot (possibly
virtual) directory.

2. Utilize $_SERVER['path_translated'] and $_SERVER{'documentRoot'] in all
the pages to temporarily set_include_path to your [virtual] DocumentRoot. 
If *those* are broken, you might as well just not use that host. :-^

3. In the config_include_path.inc, use set_include_path to set up whatever
you need to use for the new server/configuration.

So every page will set their include_path to DocumentRoot, then include a
file that from there that will change the include_path to whatever you
need for that particular server.

It's a bit of a hack, but cuts the number of config files to one (1) for a
transfer/install.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



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

2005-03-04 Thread Leif Gregory
Hello Richard,

Friday, March 4, 2005, 1:25:35 PM, you wrote:
R If *those* are broken, you might as well just not use that host.
R :-^

Your solution seems to be pretty bulletproof. I definitely appreciate
it. Just wondering though for posterity sake, have you or anyone ever
run into a host that had both $_SERVER['path_translated'] and
$_SERVER{'documentRoot'] broke? I've seen $_SERVER{'documentRoot'] not
being correct, but has anyone seen it not correct and not having
$_SERVER['path_translated'] available? Previously, when I saw
$_SERVER['documentroot'] incorrect, I didn't know about
$_SERVER['path_translated'] so I don't know if it was good or not.


R It's a bit of a hack, but cuts the number of config files to one
R (1) for a transfer/install.

Looks like it'll work. Thanks. Maybe one day the people at PHP will
fix it so we don't have to work around it.


-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

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



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

2005-03-04 Thread Richard Lynch
Leif Gregory wrote:
 Friday, March 4, 2005, 1:25:35 PM, you wrote:
 R If *those* are broken, you might as well just not use that host.
 R :-^

 Your solution seems to be pretty bulletproof. I definitely appreciate
 it. Just wondering though for posterity sake, have you or anyone ever
 run into a host that had both $_SERVER['path_translated'] and
 $_SERVER{'documentRoot'] broke? I've seen $_SERVER{'documentRoot'] not
 being correct, but has anyone seen it not correct and not having
 $_SERVER['path_translated'] available? Previously, when I saw
 $_SERVER['documentroot'] incorrect, I didn't know about
 $_SERVER['path_translated'] so I don't know if it was good or not.

Never seen it.

Only your post w/ a reference to a thread I didn't go re-read made me
think it could happen...

I don't really spend a lot of time porting code from server to server,
though.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



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

2005-03-03 Thread Richard Lynch
Leif Gregory wrote:
 http://www.devtek.org/tutorials/dynamic_document_root.php

 I'm still looking for a better way, cause this is kludgy.

include_path

-- 
Like Music?
http://l-i-e.com/artists.htm

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



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

2005-03-03 Thread Leif Gregory
Hello Richard,

Thursday, March 3, 2005, 1:15:38 PM, you wrote:
RL include_path

In the php.ini? But wouldn't that affect every virtual host on the
server? Meaning I'd have to put all the includes for every virtual
host in the same place?


Cheers,
Leif Gregory 

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

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



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

2005-03-02 Thread Chris W. Parker
Al mailto:[EMAIL PROTECTED]
on Wednesday, March 02, 2005 11:22 AM said:

 I've been using in my scripts $_SERVER['DOCUMENT_ROOT'] to find the
 base path for includes, etc.
 
 We just moved the site to a new virtual host and it doesn't work. 
 print_r() gives me:
 
 $_SERVER['document_root']= /usr/local/apache/htdocs
 $_SERVER['path_translated']= /home/user/public_html/
 
 What do you guys use for you docroot?

One option is to set your own:

?php

  $APP['document_root'] = '/wherever/you/want';

?


hth,
Chris.

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



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

2005-03-02 Thread Leif Gregory
Hello Al,

Wednesday, March 2, 2005, 12:21:58 PM, you wrote:
A What do you guys use for you docroot?

I ran into the same problem and also asked here for any ideas.

I finally ended up writing my own function to do it. You can find the
tutorial here:

http://www.devtek.org/tutorials/dynamic_document_root.php

I'm still looking for a better way, cause this is kludgy.




-- 
Leif (TB lists moderator and fellow end user).

Using The Bat! 3.0.2.3 Rush under Windows XP 5.1
Build 2600 Service Pack 2 on a Pentium 4 2GHz with 512MB

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



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

2005-03-02 Thread Tom Rogers
Hi,

Thursday, March 3, 2005, 5:21:58 AM, you wrote:
A I've been using in my scripts $_SERVER['DOCUMENT_ROOT'] to find the base path
A for includes, etc.

A We just moved the site to a new virtual host and it doesn't work.  print_r()
A gives me:

 $_SERVER['document_root']= /usr/local/apache/htdocs
 $_SERVER['path_translated']= /home/user/public_html/

A What do you guys use for you docroot?

If path_translated exists use that as it indicates a virtual website,
otherwise use document_root

-- 
regards,
Tom

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



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

2005-03-02 Thread Al
Tom Rogers wrote:
Hi,
Thursday, March 3, 2005, 5:21:58 AM, you wrote:
A I've been using in my scripts $_SERVER['DOCUMENT_ROOT'] to find the base path
A for includes, etc.
A We just moved the site to a new virtual host and it doesn't work.  print_r()
A gives me:

$_SERVER['document_root']= /usr/local/apache/htdocs
$_SERVER['path_translated']= /home/user/public_html/

A What do you guys use for you docroot?
If path_translated exists use that as it indicates a virtual website,
otherwise use document_root
If I'm reading you correctly, then a truly transportable include might look like 
this:

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

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