Forum Moderators: coopster
Here's my problem...
I want to include a file in a PHP source, and the file is in my home directory.
I pretty soon stumbled upon this, which nearly works....
<?php set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] ); ?>
Here's my problem...
On my ISP, the code picks up the path where my website is stored and adds it to '.'.
On the Mac, the code adds /Library/Webserver/Documents (instead of /~username) to '.'
But it's more curious still...
Take the case that the file I want to include is in my top level directory, and my PHP is two levels down, inside a folder in a folder...
On the ISP, if I include "filename", all is well. It goes up two levels and includes it.
On the Mac, it looks inside the current directory and fails.
If I include "/filename" instead, then my ISP fails - it goes to the top of the virtual server.
But it works on the Mac - the Mac adds ../.. to an include /filename (as I can demonstrate by trying to include "/absentfile" - it warns me that ../../absentfile is, well, absent.
What do I need to do to that code snippet to make it so that I can include a file in the home directory on both my Mac and my ISP with the same PHP?
Thanks!
DerekH
I prefer just using the include/require based on an "includes" directory. Then I set the path to this directory in either Apache httpd.conf or an .htaccess file.
php_value include_path [php.net] "/path/to/includes:.:/path/to/PEAR"
Here is a thread from our PHP Forum Library [webmasterworld.com] regarding includes that may be handy:
Control your included files [webmasterworld.com]