PJ wrote:
Michael A. Peters wrote:
PJ wrote:

I hope I'm not out of place here, but I have a problem that seems to be
I am using some include statements for page headers with the pages in
various directories on the site. The problem is this... if I put
relative statements in the page (header.php) like ../images/file.jpg and
../file.php etc, if the page into which I include header.php is not in
the top level directory, the links do not work and I have to copy
header.php to header1.php and change the references to /images otherwise
images are not displayed and links to not work in href.

1.  top level file books.php
include ("lib/db1.php");    // Connect to database
include ("header1.php");

2. subdirectory: /authors/a.php
include "../header.php";

I thought that using referencing the top level of the directory tree
(../) would work form anywhere within the tree?
Am I the victim of my own misconceptions here?
TIA to set me straight.
Easy to solve.
I neglected to mention, although, it must be fairly obvious that I'm
fairly new to all this ["newbie" but not virgin :-) ]
Comments below -->

1. Where to I put it?
2. srv = ? domain = ? phpinclude = ? record, process... = ? server, but
like what? a url?

/srv/domain/phpinclude is just an example directory path.

/var/www or /usr/www are other common examples.

If your server is Windows, I don't have any experience with how php sees windows file paths, but I believe it still uses a unix like forward slash syntax.

Then just call it without path - IE


php will first look for foo.inc in /srv/domain/phpinclude, then in
/srv/domain/record_include, etc.

make directories for your includes, preferably outside the web root,
and define your include path at the top of your script.

I personally don't like to have . as part of my include path, and
relative include paths (id somedir/foo.inc) are IMHO an even worse
What do you suggest as a better prctice?

I make application specific directories for include files, and put all include files into that application specific directory (application mean web application). Sometimes I have more than one if it is a big web application.

Doing it that way allows me to include the same files with several webapps on the same server, lets me move the php files around etc. without needing to worry about moving the include files, because the directory where they are served from is part of the include path.

It makes upgrading web apps a lot easier - often times you can leave the individual php files alone, it's the include files that get updated. So when you are developing a new improved version of your web app, you can just upload the new directory to your production server and change one line in the actual php file (where you define the include_path) and your web app is updated - making it cake to roll back a week later if you find you need to.

Separate the pages that are actually served from the pages that are included. It makes a lot of things easier down the road.

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

Reply via email to