| |||||||||||
| |||||||||||
really stupid question Posted by bschultz (bschultz), 11 July 2003 Why doesn't this: Code:
work...but using the full url Code:
does work? I should say that I'm trying to includeheader.htm from the root directory to every other directory that uses the include. Posted by admin (Graham Ellis), 11 July 2003 If you're giving an absolute path starting with a /, it also needs to include the document root - so you'll be looking for something likeinclude ("/home/bschultz/htdocs/include.htm"); Suggestion - keep your include files in a quite separate directory that's not in the document tree (htdocs, html, public_html or whatever it's called). That way, there is no danger of anyone calling up the include file directly via its URL. Posted by waygood (waygood), 11 July 2003 The document root can be retrieved using $_SERVER["DOCUMENT_ROOT"]I develop in this manner commercially, having seperate directories for the include to hide them away from prying eyes. In our webspace we have directories 'www' and 'includes'. The website setting are then changed to point to the www directory, so the doc root and includes are never viewable by a web browser. Posted by bschultz (bschultz), 11 July 2003 well, here's the real problem...I run a Windows server at home as a test server...and my "live" server is linux...so the paths will be different for each server. Is there anyway to have a text file or something that I can use to tell the absolute path...and then just change the one file once I go "live"?For instance, on the test server, the path would be: c:/program files/apache group/apache/htdocs/somefile.htm and on the live server it would be: home/username/directory/somefile.htm Thanks! Posted by AlanMacDonald (AlanMacDonald), 11 July 2003 Can't give code (Haven't taken the php course yet ![]() $includeFileDir = "c:/program files/apache group/apache/htdocs/"; or whatever. Use the value of $includeFileDir whenever building file+path strings. Basically, abstract the path to a variable in an included cfg file, and change the cfg file when the path changes. Posted by John_Moylan (jfp), 11 July 2003 In answer to the second question:The config file (as Alan stated) is the route I take too. I tend to use constants to populate it. I have a file called host.cfg which you can change for Windows/Linux/Mac without having to change your scripts. host.cfg contains: <?php define(INCLUDEPATH, '/www/php_configs/'); define(HOSTNAME, 'localhost'); define(USERNAME, 'something'); define(PASSWORD, 'n0tR3@lp@55w0rd'); ?> Scripts contain: include('/i/need/fullpath/to/includes/host.cfg'); include(INCLUDEPATH.'/classes/helper.php'); my mysql username is USERNAME my mysql password is PASSWORD it nice for moving stuff between machines. jfp Posted by bschultz (bschultz), 11 July 2003 with this setupQuote:
wouldn't I have to change every page when the path changes ![]() Posted by admin (Graham Ellis), 11 July 2003 Wow - busy thread - thanks eveyone - keep it coming. All excellent stuff.Couple of additional comments: 1. Certain Servers don't set the Document Root, so you can't rely on it 100%. 2. Yes - use an include file so that you only have to set it up once and can then include it in all the pages. Our whole web site is PHP (even though there are lots of .html extensions), and all pages except one use a single include file for the common stuff, using a ../../xxxxxx type notation. One of the things it does is look at the address of the server so that it can work out where it's running and what the path is. Port to a new server? Just one lookup to change, and we can go between very different directory structures; other data and included files can then be absolute. Posted by AlanMacDonald (AlanMacDonald), 14 July 2003 Hi,on 07/11/03 at 18:05:30, bschultz wrote:
I see your issue. It's kinda complicated. Hmmm. Thinks (scratches head) Ah ha! (light goes on) All you need to do is make sure that your included config file is called relative to the current active file, e.g. include ('./config_data/config.cfg'); for a file in the same directory, or for a file in the 'foo' folder: include ('../config_data/config.cfg'); Basically, each file contains a hard coded, relative link to where the main config file is. Everything else you can manage to abstract is declared in the config.cfg file, and referenced by all files that make up your project. The only time you would need to change this hard coding is if you change the locations of any files relative to the location of the config file. Now someone is going to say 'why not store the path ./config_data/ into a variable and do include ($ConfigPath."config.cfg"); instead'. Well, then you start to recurse. Where do you define $ConfigPath and make it available to all parts of the project? How do you define the path to the configuration file containing the path to the configuration file..... [wet smashing sound] Sorry My brain just imploded. Hope this makes sense ![]() Posted by bschultz (bschultz), 15 July 2003 Hi all...thanks for all the help on this issue. I was told by my host that phpsuexec wasn't enabled on the server. So, no relative paths would work, and placing a php.ini file in the directory wouldn't even work. So, I needed to place the following in the .htaccess file:php_value include_path ".:my/path/goes/here" Again, thanks for everything. Brian This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |