Re: Full versus relative URLs

From: Date: Tue, 17 Feb 2009 20:30:27 +0000
Subject: Re: Full versus relative URLs
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-288487@lists.php.net to get a copy of this message
2009/2/17 PJ <af.gourmet@videotron.ca>: > Dotan Cohen wrote: >>>> So put it all in one place: >>>> >>>> <?php >>>> include "path.inc"; >>>> print"<a href=\"$path/dir/file.php\">"; >>>> ?> >>>> >>>> Full URLs don't break when users save the pages to disk. >>> That would be fine if the pages weren't being crafted in Dreamweaver, >>> where inserting links like that is a pain. >>> >> >> For that you'd have to ask on the Dreamweaver list. I don't really >> like those tools. >> > 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. Personally I always include files relative to my current location using the following... include dirname(__FILE__).'/lib/db1.php'; That way it doesn't matter how INI vars are set up and I don't need to fanny around with setting them at runtime. -Stuart -- http://stut.net/

« previous php.general (#288487) next »