|
Posted by Jim Moe on 02/17/07 01:27
dorayme wrote:
>>
>> <?php include 'footer.inc'; ?>
>>
>> So how does PHP know where footer.inc is kept? By setting the
>> "include_path" setting in "php.ini", ".htaccess", "httpd.conf"
>> or similar. Of course, if you are on shared hosting, you may
>> need to check that it is possible for you to adjust the
>> include_path.
>
> I am sort of following you here, the trouble is that I am a bit
> lost over fine controls over the Windows servers concerned.
>
>
Use the ini_set() function to change the value of include_path. The
disadvantage is that the setting only lasts for the session.
For a fully DIY method there is this. <base_dir.inc> provides a set of
custom directory strings created at the start of a session:
<?php
if (eregi('example.com', $_SERVER['SERVER_NAME'])) { // Local copy?
$base_dir1 = 'f:/pub/websites/';
$base_dir2 = $base_dir1 . 'sma-improved/';
}
else { // Must be the WWW
$base_dir1 = '/usr/local/apache/';
$base_dir2 = $base_dir1 . 'htdocs/';
}
?>
which is called by
function globals_init ($start_path)
{
global // If they weren't global before, they are now.
$base_dir1,
$base_dir2;
if (!isset($base_dir1)) {
$val = $start_path . 'base-dir.inc';
require($val); // Assigns $base_dir1 ..., here.
}
// ...whatever else you want set up...
}
This must be at the top of every PHP page:
require('./path/to/globals-init.inc');
globals_init('./path/to/base_dir/');
The advantage is the option to create a number of base directory paths.
It has its weaknesses, of course. The main being the need to prepend
base_dir1 (or base_dir2, ...) to the relative paths.
--
jmm (hyphen) list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Navigation:
[Reply to this message]
|