Re: [PHP] SOLVED: Re: [PHP] Document root, preferred way to find it???
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???
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
[PHP] SOLVED: Re: [PHP] Document root, preferred way to find it???
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???
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