Here is a silly question
13 answers - 1137 bytes -

Hi,
This is come thing that I have struggled with now and again. I usaually
us php code to make it work, but was wondering how others deal with this
I use includes in most of the web applications that I work on to include
the header, footer, menu etc.
The problem that I always run into as a project gets bigger is my links
to pages. If all the files are in the root directory theres no problem.
If I have some files in a folder and call my menu for example <?
include("/menu.php"); ?I have to call if from the parent
directory. But then of course
all the links are wrong. Root becomes the calling directory.
I usually use a php variable to place the / if its needed.
How does everyone else deal with this type of problem. I have a times
places an extra copy of the footer, menu, header etc in each directory
but it is a pain to change links
when you have multiple locations to do it in.
Thanks for any suggestions.
I would be nice to have a simple way to have my include files in a
common place that works and keeps the links right.
Scandog
No.1 | | 1400 bytes |
| 
Hello,
I refer to the target file like this:
<?php
include $_SERVER['DCUMENT_RT'] . '/menu_dir/menu.php';
?>
Solves the problem.
Sudheer. S
Mon, 2006-04-03 at 09:54 -0600, Mace Eliason wrote:
Hi,
This is come thing that I have struggled with now and again. I usaually
us php code to make it work, but was wondering how others deal with this
I use includes in most of the web applications that I work on to include
the header, footer, menu etc.
The problem that I always run into as a project gets bigger is my links
to pages. If all the files are in the root directory theres no problem.
If I have some files in a folder and call my menu for example <?
include("/menu.php"); ?I have to call if from the parent
directory. But then of course
all the links are wrong. Root becomes the calling directory.
I usually use a php variable to place the / if its needed.
How does everyone else deal with this type of problem. I have a times
places an extra copy of the footer, menu, header etc in each directory
but it is a pain to change links
when you have multiple locations to do it in.
Thanks for any suggestions.
I would be nice to have a simple way to have my include files in a
common place that works and keeps the links right.
Scandog
No.2 | | 1588 bytes |
| 
I tend to stick "/nav/header.php" in for my includes, since I control
the server.
As long as the site translates root to the main directory of your
website and not somewhere else, you can always have your links be
"/menu.php" as server-speak "/" means rootme.
I also use "/" in my href links in my menus and such so that no matter
where the script is called from, it always works.
Robert
Mace Eliason wrote:
Hi,
This is come thing that I have struggled with now and again. I usaually
us php code to make it work, but was wondering how others deal with this
I use includes in most of the web applications that I work on to include
the header, footer, menu etc.
The problem that I always run into as a project gets bigger is my links
to pages. If all the files are in the root directory theres no problem.
If I have some files in a folder and call my menu for example <?
include("/menu.php"); ?I have to call if from the parent
directory. But then of course
all the links are wrong. Root becomes the calling directory.
I usually use a php variable to place the / if its needed.
How does everyone else deal with this type of problem. I have a times
places an extra copy of the footer, menu, header etc in each directory
but it is a pain to change links
when you have multiple locations to do it in.
Thanks for any suggestions.
I would be nice to have a simple way to have my include files in a
common place that works and keeps the links right.
Scandog
No.3 | | 1950 bytes |
| 
Apr 3, 2006, at 10:54 AM, Mace Eliason wrote:
Hi,
This is come thing that I have struggled with now and again. I
usaually us php code to make it work, but was wondering how others
deal with this
I use includes in most of the web applications that I work on to
include the header, footer, menu etc.
The problem that I always run into as a project gets bigger is my
links to pages. If all the files are in the root directory theres
no problem.
If I have some files in a folder and call my menu for example <?
include("/menu.php"); ?I have to call if from the parent
directory. But then of course
all the links are wrong. Root becomes the calling directory.
I usually use a php variable to place the / if its needed.
How does everyone else deal with this type of problem. I have a
times places an extra copy of the footer, menu, header etc in each
directory but it is a pain to change links
when you have multiple locations to do it in.
Thanks for any suggestions.
I would be nice to have a simple way to have my include files in a
common place that works and keeps the links right.
Scandog
, I this may only help part of your problem. Within your "menu.php"
file, you could make all the links absolute:
<a href="/root/to/a/location.php">Place A</a>
<a href="/root/to/somewhere.php">Place B</a>
instead of relative:
<a href="location.php">Place A</a>
<a href="somewhere.php">Place B</a>
That means you can use only 1 menu.php file and all the links will
work from wherever. course, this does not fix this issue:
<? include ("//menu.php"); ?or
<? include ("menu.php"); ?or
<? include ("/somewhere/menu.php"); ?>
for each of your files that includes the menu. Maybe another clever
person has an idea.
~Philip
No.4 | | 3450 bytes |
| 
I'm not exactly sure but I think that include() may not work this
way:
<? include ("/menu.php"); ?>
I don't think it knows to go to the root and then look for menu.php.
That's why you have to tell it exactly where the menu.php is found -
1 level back:
<? include ("/menu.php"); ?>
Maybe it should be labeled as a bug? Hehehe! ;)
~Philip
Apr 3, 2006, at 11:18 AM, Mace Eliason wrote:
I gave it a try and this is one thing I ran into.
in my menu file I changed all the links to <a href="/
index.php">Home</a>
then in a file in another directory I added this <? include("/
menu.php"); ?This didn't work
if I changed it to
<? include("/menu.php"); ?This worked and the links work fine.
Seems strange the first include didn't work. Shouldn't it goto the
root of the website and look from there?
>
>
>
>
Philip Thompson wrote:
>Apr 3, 2006, at 10:54 AM, Mace Eliason wrote:
>>
Hi,
This is come thing that I have struggled with now and again. I
usaually us php code to make it work, but was wondering how
others deal with this
I use includes in most of the web applications that I work on to
include the header, footer, menu etc.
The problem that I always run into as a project gets bigger is my
links to pages. If all the files are in the root directory
theres no problem.
If I have some files in a folder and call my menu for example <?
include("/menu.php"); ?I have to call if from the parent
directory. But then of course
all the links are wrong. Root becomes the calling directory.
I usually use a php variable to place the / if its needed.
How does everyone else deal with this type of problem. I have a
times places an extra copy of the footer, menu, header etc in
each directory but it is a pain to change links
when you have multiple locations to do it in.
Thanks for any suggestions.
I would be nice to have a simple way to have my include files in
a common place that works and keeps the links right.
Scandog
>>
>>
>, I this may only help part of your problem. Within your
>"menu.php" file, you could make all the links absolute:
>>
><a href="/root/to/a/location.php">Place A</a>
><a href="/root/to/somewhere.php">Place B</a>
>>
>instead of relative:
>>
><a href="location.php">Place A</a>
><a href="somewhere.php">Place B</a>
>>
>That means you can use only 1 menu.php file and all the links will
>work from wherever. course, this does not fix this issue:
>>
><? include ("//menu.php"); ?or
><? include ("menu.php"); ?or
><? include ("/somewhere/menu.php"); ?>
>>
>for each of your files that includes the menu. Maybe another
>clever person has an idea.
>>
>~Philip
No.5 | | 3681 bytes |
| 
<?php include("/nav/menu.html") ?works like a charm for me, but your
mileage may vary depending on who has set up your website and what
server it is being run on.
FYI: I build my menu's with HTML and javascript, hence the .html call,
but it should be fine as php as well.
Robert
Philip Thompson wrote:
I'm not exactly sure but I think that include() may not work this way:
<? include ("/menu.php"); ?>
I don't think it knows to go to the root and then look for menu.php.
That's why you have to tell it exactly where the menu.php is found - 1
level back:
<? include ("/menu.php"); ?>
Maybe it should be labeled as a bug? Hehehe! ;)
~Philip
Apr 3, 2006, at 11:18 AM, Mace Eliason wrote:
>I gave it a try and this is one thing I ran into.
>>
>in my menu file I changed all the links to <a href="/index.php">Home</a>
>>
>then in a file in another directory I added this <?
>include("/menu.php"); ?This didn't work
>>
>if I changed it to
><? include("/menu.php"); ?This worked and the links work fine.
>>
>Seems strange the first include didn't work. Shouldn't it goto the
>root of the website and look from there?
>>
>>
>>
>>
>Philip Thompson wrote:
Apr 3, 2006, at 10:54 AM, Mace Eliason wrote:
Hi,
This is come thing that I have struggled with now and again. I
usaually us php code to make it work, but was wondering how others
deal with this
I use includes in most of the web applications that I work on to
include the header, footer, menu etc.
The problem that I always run into as a project gets bigger is my
links to pages. If all the files are in the root directory theres
no problem.
If I have some files in a folder and call my menu for example <?
include("/menu.php"); ?I have to call if from the parent
directory. But then of course
all the links are wrong. Root becomes the calling directory.
I usually use a php variable to place the / if its needed.
How does everyone else deal with this type of problem. I have a
times places an extra copy of the footer, menu, header etc in each
directory but it is a pain to change links
when you have multiple locations to do it in.
Thanks for any suggestions.
I would be nice to have a simple way to have my include files in a
common place that works and keeps the links right.
Scandog
, I this may only help part of your problem. Within your "menu.php"
file, you could make all the links absolute:
<a href="/root/to/a/location.php">Place A</a>
<a href="/root/to/somewhere.php">Place B</a>
instead of relative:
<a href="location.php">Place A</a>
<a href="somewhere.php">Place B</a>
That means you can use only 1 menu.php file and all the links will
work from wherever. course, this does not fix this issue:
<? include ("//menu.php"); ?or
<? include ("menu.php"); ?or
<? include ("/somewhere/menu.php"); ?>
for each of your files that includes the menu. Maybe another clever
person has an idea.
~Philip
General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
No.6 | | 4239 bytes |
| 
I'm very interested to see the best option for this.
Currently I set 2 variables in the include file (header.inc)
$siteurl = "http://www.yourdomain.com/ <http://www.yourdomain.com/psp/>";
$pathto = "/";
Then for includes I do something like:
include($pathto."functions.php");
And for images, links, etc.
<img src="<?php echo $siteurl; ?>nav/images/image.jpg"
Hope this helps, but I'm sure there's another way?!?
03/04/06, Wolf <LoneWolf (AT) nc (DOT) rr.comwrote:
<?php include("/nav/menu.html") ?works like a charm for me, but your
mileage may vary depending on who has set up your website and what
server it is being run on.
FYI: I build my menu's with HTML and javascript, hence the .html call,
but it should be fine as php as well.
Robert
Philip Thompson wrote:
I'm not exactly sure but I think that include() may not work this
way:
<? include ("/menu.php"); ?>
I don't think it knows to go to the root and then look for menu.php.
That's why you have to tell it exactly where the menu.php is found - 1
level back:
<? include ("/menu.php"); ?>
Maybe it should be labeled as a bug? Hehehe! ;)
~Philip
--
Apr 3, 2006, at 11:18 AM, Mace Eliason wrote:
>
>I gave it a try and this is one thing I ran into.
>>
>in my menu file I changed all the links to <a
href="/index.php">Home</a>
>>
>then in a file in another directory I added this <?
>include("/menu.php"); ?This didn't work
>>
>if I changed it to
><? include("/menu.php"); ?This worked and the links work fine.
>>
>Seems strange the first include didn't work. Shouldn't it goto the
>root of the website and look from there?
>>
>>
>>
>>
>Philip Thompson wrote:
Apr 3, 2006, at 10:54 AM, Mace Eliason wrote:
Hi,
This is come thing that I have struggled with now and again. I
usaually us php code to make it work, but was wondering how others
deal with this
I use includes in most of the web applications that I work on to
include the header, footer, menu etc.
The problem that I always run into as a project gets bigger is my
links to pages. If all the files are in the root directory theres
no problem.
If I have some files in a folder and call my menu for example <?
include("/menu.php"); ?I have to call if from the parent
directory. But then of course
all the links are wrong. Root becomes the calling directory.
I usually use a php variable to place the / if its needed.
How does everyone else deal with this type of problem. I have a
times places an extra copy of the footer, menu, header etc in each
directory but it is a pain to change links
when you have multiple locations to do it in.
Thanks for any suggestions.
I would be nice to have a simple way to have my include files in a
common place that works and keeps the links right.
Scandog
, I this may only help part of your problem. Within your "menu.php"
file, you could make all the links absolute:
<a href="/root/to/a/location.php">Place A</a>
<a href="/root/to/somewhere.php">Place B</a>
instead of relative:
<a href="location.php">Place A</a>
<a href="somewhere.php">Place B</a>
That means you can use only 1 menu.php file and all the links will
work from wherever. course, this does not fix this issue:
<? include ("//menu.php"); ?or
<? include ("menu.php"); ?or
<? include ("/somewhere/menu.php"); ?>
for each of your files that includes the menu. Maybe another clever
person has an idea.
~Philip
General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
No.7 | | 1549 bytes |
| 
I put all the generic include files such as the header and menu in their
own directory. Then I put that directory in the include_path ini
variable. I would normally set it in the virtualhost file but .htaccess
should work as well, you can even set it in the script.
This means I can simply include the file using:
<?php include("menu.php"); ?>
David
Mace Eliason wrote:
Hi,
This is come thing that I have struggled with now and again. I usaually
us php code to make it work, but was wondering how others deal with this
I use includes in most of the web applications that I work on to include
the header, footer, menu etc.
The problem that I always run into as a project gets bigger is my links
to pages. If all the files are in the root directory theres no problem.
If I have some files in a folder and call my menu for example <?
include("/menu.php"); ?I have to call if from the parent
directory. But then of course
all the links are wrong. Root becomes the calling directory.
I usually use a php variable to place the / if its needed.
How does everyone else deal with this type of problem. I have a times
places an extra copy of the footer, menu, header etc in each directory
but it is a pain to change links
when you have multiple locations to do it in.
Thanks for any suggestions.
I would be nice to have a simple way to have my include files in a
common place that works and keeps the links right.
Scandog
No.8 | | 2042 bytes |
| 
At 9:54 AM -0600 4/3/06, Mace Eliason wrote:
>Hi,
>
>This is come thing that I have struggled with now and again. I
>usaually us php code to make it work, but was wondering how others
>deal with this
>
>I use includes in most of the web applications that I work on to
>include the header, footer, menu etc.
>
>The problem that I always run into as a project gets bigger is my
>links to pages. If all the files are in the root directory theres
>no problem.
>
>If I have some files in a folder and call my menu for example <?
>include("/menu.php"); ?I have to call if from the parent
>directory. But then of course
>all the links are wrong. Root becomes the calling directory.
>
>I usually use a php variable to place the / if its needed.
>
>How does everyone else deal with this type of problem. I have a
>times places an extra copy of the footer, menu, header etc in each
>directory but it is a pain to change links
>when you have multiple locations to do it in.
>
>Thanks for any suggestions.
>
>I would be nice to have a simple way to have my include files in a
>common place that works and keeps the links right.
>
>Scandog
Mace:
I do it like you do and live with it.
I keep all my common includes in one include folder. If I move a
project folder down a level, then I change all my includes in it like
-- 'include( "includes/opendb.php")' to 'include(
"/includes/opendb.php")' .
However, I have given it some thought about changing it to an
absolute url like --
$_SERVER['DCUMENT_RT'] . "/includes/opendb.php"
-- and that way then it doesn't matter how deep you go with your projects.
So, now that you mentioned it -- I think I'll change it. I can do an
entire site find/replace in GoLive.
Thanks for asking.
tedd
No.9 | | 1278 bytes |
| 
Nobody else has mentioned it, so I thought I would.
http://smarty.php.net - PHP Templating Engine
Mace Eliason wrote:
Hi,
This is come thing that I have struggled with now and again. I
usaually us php code to make it work, but was wondering how others
deal with this
I use includes in most of the web applications that I work on to
include the header, footer, menu etc.
The problem that I always run into as a project gets bigger is my
links to pages. If all the files are in the root directory theres no
problem.
If I have some files in a folder and call my menu for example <?
include("/menu.php"); ?I have to call if from the parent
directory. But then of course
all the links are wrong. Root becomes the calling directory.
I usually use a php variable to place the / if its needed.
How does everyone else deal with this type of problem. I have a times
places an extra copy of the footer, menu, header etc in each directory
but it is a pain to change links
when you have multiple locations to do it in.
Thanks for any suggestions.
I would be nice to have a simple way to have my include files in a
common place that works and keeps the links right.
Scandog
No.10 | | 242 bytes |
| 
At 5:56 AM +1000 4/4/06, Peter Hoskin wrote:
>Nobody else has mentioned it, so I thought I would.
>
>http://smarty.php.net - PHP Templating Engine
>
And that goes somewhere?
tedd
No.11 | | 428 bytes |
| 
Site must be down search google for site:smarty.php.net
Believe me, it does exist.
tedd wrote:
At 5:56 AM +1000 4/4/06, Peter Hoskin wrote:
>Nobody else has mentioned it, so I thought I would.
>>
>http://smarty.php.net - PHP Templating Engine
>>
>
>
And that goes somewhere?
tedd
No.12 | | 472 bytes |
| 
Well, it did, looks like someone's having server issues or forgot to pay
the bill.
Anyways, here's Google's cache of it:
tedd wrote:
At 5:56 AM +1000 4/4/06, Peter Hoskin wrote:
>Nobody else has mentioned it, so I thought I would.
>>
>http://smarty.php.net - PHP Templating Engine
>>
And that goes somewhere?
tedd
No.13 | | 1400 bytes |
| 
Mace Eliason wrote:
Hi,
This is come thing that I have struggled with now and again. I usaually
us php code to make it work, but was wondering how others deal with this
I use includes in most of the web applications that I work on to include
the header, footer, menu etc.
The problem that I always run into as a project gets bigger is my links
to pages. If all the files are in the root directory theres no problem.
If I have some files in a folder and call my menu for example <?
include("/menu.php"); ?I have to call if from the parent
directory. But then of course
all the links are wrong. Root becomes the calling directory.
I usually use a php variable to place the / if its needed.
How does everyone else deal with this type of problem. I have a times
places an extra copy of the footer, menu, header etc in each directory
but it is a pain to change links
when you have multiple locations to do it in.
Thanks for any suggestions.
I would be nice to have a simple way to have my include files in a
common place that works and keeps the links right.
Scandog
I didn't see anybody else mention this, so:
$mydir = dirname(__FILE__);
include($mydir . '//nav/menu.php');
works every time and you don't have to rely on document_root being set
properly etc.