Relative paths from file for img, a and header

it looks like you are running your php on a localhost so


is returning a directory ie "C:\validation..."

try using

 "'http: //' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/include'"

as your include path

Got it working on local host AND online, here is my setup so:

1) You may use it yourself 2) Give a better alternative to us newbies

I used what zoranc said above. For example, to get CSS to work on the dynamic-pretty-url pages, I set it up as:

print "<link href='http://" . $_SERVER['HTTP_HOST'] .'/' . dirname($_SERVER['PHP_SELF']) . "/CSS/main.css' rel='stylesheet' type='text/css' />";


WARNING: the code above will produce links such as Domain///CSS. I still need to filter the extra slashes out, but it works even as it is for the CSS and everything else (img, a, php headers)

Then I had to do this everytime I wanted to:

  1. Create a dynamic link
  2. Create a dynamic img
  3. Even for my header form! Since my header is always included, when you are browsing pretty-urls, your form can't have action='header.php', because it will then try to find it on whatever pretty-url you are currently browsing (domain/category/article and so on). You'll have to use header='" php the solution we are discussion/header.php endphp.

    Again, be warned this produces extra slashes and you'll have to remove them somehow.

    With this setup you can have a site that works on your localhost and any web host without the need to change code, but it is somewhat cumbersome and error prone to use. If anyone has a better solution please share.

    This works well enough and in my opinion is definitely better than having to change code when you upload your site everytime, which is even more error prone I suppose.

    Thanks again Zoranc, really helpful.