Hello all!
I have a small PHP problem cocerning include & pathnames...
I've searched all over several message forums, but I haven't found an answer to my problem...
I want to use the include feature to "put together" the pages of my homepage... that means take a header and a footer htm file as well as another htm file dependent on user input.
That means I want to have a file called for example main.php and be able to call it with main.php?section=music to load the "music" page for example.. (I'd do a switch-case in main.php to load the proper htm file)
The problem are the path-names when doing the includes. My structure is as follows:
--root //header.htm, footer.htm, main.php...
|
+-- music // Subdir containing all the files used in this section..
| // most importantly: music.htm
|
+-- other section...
If I load the music.htm file from the main.php file, the links used in
music.htm are not valid as their path is relative to the subdir...
I tried using the chdir() functions in PHP, but it seems this only changes the working dir of the PHP-script.. the browser still looks in the wrong dir...
I have thought of several solutions for this problem, but none pleases me as they all involve either too much work or too many downsides.
1) Easiest solution: I could change the links in every htm file. It would take quite a lot of time, and I would not be able to view my htm files directly; only through a main.php call...
If I change everything to absolute pathnames, I wouldn't be able to view my homepage offline anymore.. (which would suck)
2) I could make a "dummy" php file in every directory just to include the main.php from there... I'd still have the whole system depedent on just the main.php (which is what I want), but this seems like a very "ugly" solution to me. 😉
I think there must another way of solving this in more or less clean way without rearranging the entire structure of my site...
Any suggestions??
Thanks in advance
Lorenz