relative vs. absolute links in php driven pages?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
If you are dynamically loading pages, through php, from inside a folder that
have relative links to images inside the same folder, into another document
(a template) in a different folder level, the links will be broken.

Is there some magic trick to dealing with this, or is it just better to
never use relative links in a site that will be dynamically driven with php?

Stephen Kay

Re: relative vs. absolute links in php driven pages?

Stephen Kay wrote:

Quoted text here. Click to load it


Well, several opinions on this subject.
my 2 cents:

Your problem manifests in many forms, also with includes.
I made it a habbit to make a config-file for each PHP-project, and make a  
simple function (or constant) in there that points to eg:
- absolute path (URI) to imagedirectory
something like:
function getRootDirImages(){
  return " /";

You can do the same for includes, but it is easier to overwrite a php.ini  
setting for each script named include_path.
use ini_set() for that.

If you include both above every script, you have easy acces to all your  

More solutions exists, but I like this one because it is easy and clean.

Erwin Moller

Site Timeline