Re: Full versus relative URLs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



PJ wrote:


I hope I'm not out of place here, but I have a problem that seems to be
related.
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.

e.g.:
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.

ini_set("include_path", "/srv/domain/phpinclude:/srv/domain/record_include:/srv/domain/process_include");

Then just call it without path - IE

include('foo.inc');

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 practice.

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux