PHP virtual paths…

February 13th, 2003

…are a sodding mystery to me! I decided to make my life easier by using PHP included files to write the header, footer and other static stuff on the pages of this site. Was this a good idea? Well, in theory yes. Having the header and footer in separate files means I only have to update them once and the change is reflected across the site. However, for some reason, PHP include files do not let you use a virtual path. Consider this:

<? include("/includes/"); ?>

This line of code uses a ‘virtual’ path to the folder ‘includes’ containing the file ‘’. The forward slash stands for the site root. This is useful because we don’t want to be having loads of relative URLs all over the place like:

<? include("../includes/"); ?>

<? include("../../includes/"); ?>

etc. With most other web-related stuff you can use the virtual url system, just not with PHP. I’m trying to work out how to do this so I can get rid of the Dreamweaver template system that I’ve been using ever since my host lost all CGI ability (and therefore, Movable Type).

Not being an expert in PHP, I tend to search the web for answers. This time I have drawn a blank. I’m hoping somebody will see this and get in touch. Until I can solve this vexing riddle, you will get some very basic looking pages: mailing list, css emporium to name a few.

**UPDATE** This started annoying me so much so that I’ve completely abandoned the Dreamweaver templates and hand coded the individual relative URLs on each page. I guess at some point I’ll work out how to do what I need to do. For now, as with much to do with this site over the last month, I will cope.


3 Responses to “PHP virtual paths…”

  1. mario

    Maybe I can help you out: Try to use absolute paths! That way you need to specify that path only once and it is same from wherever you access your file.. for example – instead: (“/includes/”); use: (“home/user01/www/includes/”);
    Hope that helps,

  2. Guy

    Cheers Mario, that’s a big help.

  3. Cor

    You can use the following in your templates: