Click to See Complete Forum and Search --> : php navigation menu help


calrockx
11-24-2003, 08:32 PM
so i'm very new at php and with a friend's help i figured out how to put a <? include("other/refer/menu.htm");?> on a webpage to call in the menu. i did this because every page on the site i'm working on has the same menu on the left for easy navigation. so if i ever need to make a change on it, i could just edit the one and it's called to all the other pages.

but i just realized, the link paths won't be correct. right now they're all set according to the initial index page on the menu.htm. so is there a way that i can call this menu to each page in various folders and still have the links work, no matter where they're called?

pyro
11-24-2003, 10:29 PM
Use a root path:

<?PHP
include $_SERVER['DOCUMENT_ROOT']."/other/refer/menu.htm";
?>

The $_SERVER['DOCUMENT_ROOT'] will get your document root, so the path you have to set will be just like setting an absolute path to your file.

calrockx
11-24-2003, 10:37 PM
Originally posted by pyro
Use a root path:

<?PHP
include $_SERVER['DOCUMENT_ROOT']."/other/refer/menu.htm";
?>

The $_SERVER['DOCUMENT_ROOT'] will get your document root, so the path you have to set will be just like setting an absolute path to your file.

thanks for the help. so i add that $ document root thing, and in the menu.htm i just type the website address for the link, <A HREF="http://www.insertwebpagehere.com"> and that's it?

pyro
11-24-2003, 10:40 PM
No, you need to use a root path from the server. So, if you would type http://www.yoursite.com/blah/foo.php to get to the page you want to include, you'd use something like this:


<?PHP
include $_SERVER['DOCUMENT_ROOT']."/blah/foo.php";
?>

calrockx
11-24-2003, 10:48 PM
Originally posted by pyro
No, you need to use a root path from the server. So, if you would type http://www.yoursite.com/blah/foo.php to get to the page you want to include, you'd use something like this:


<?PHP
include $_SERVER['DOCUMENT_ROOT']."/blah/foo.php";
?>

sorry to be dumb, but i'm really not familiar with web design much past html, css and a litte javascript. okay in the web page i want to call the menu, say history.php, i put

<?PHP
include $_SERVER['DOCUMENT_ROOT']."/blah/foo.php";
?>
or does that code go in the menu.htm page in between the A HREF quotes? or instead of the A HREF tag?

and are all the paths based on an index page perspective?

pyro
11-24-2003, 10:57 PM
Alright, let me try to explain it better - I'm going to assume it is a Linux/Unix server, as most are:

The document root, is the root path to your site. Basically, it is the path from the servers root to the directory that your files are stored in. So, if the servers main directory is called root, all users are stored in a directory named users, and your directory is called user1, the root path would look like this:

/root/users/user1

Now, if you want to include your index.php page, you would use a path like this:

/root/users/user1/index.php

But, since I wanted to make it easy on you, I used $_SERVER['DOCUMENT_ROOT'], which will automatically get the document root for you. So, in the index.php example, you'd use:

$_SERVER['DOCUMENT_ROOT']."/index.php"

So, if you want to include a file that is in a directory named includes, you use:

include "$_SERVER['DOCUMENT_ROOT']."/includes/file.php"

That will include whatever code is in file.php, just like if you had typed it ine.

calrockx
11-24-2003, 11:22 PM
:(

okay, i think i'm gettin what you were saying on the php. just to clarify...


this is the menu i have saved in menu.htm


<HEAD>
<LINK HREF="template.css" NAME="template" REL="stylesheet" TYPE="text/css">
</HEAD>



<TABLE BGCOLOR=#A0522D WIDTH=130 STYLE="font-size: 09pt; color: white">

<TR>
<TD BGCOLOR=white CLASS="SolidBlack" ALIGN=CENTER>
<FONT CLASS="section">
<A HREF="therunner/index.htm">THE 4RUNNER</A></FONT></TD>
</TR>
<!-- Information -->
<TR>
<TD CLASS="highlight1"><A HREF="http//www.calrockx.com/4runner/therunner/information/index.htm">INFORMATION</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/therunner/information/history.htm">- History</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/therunner/information/specifications.htm">- Specifications</A></TD>
</TR>




<TR>
<TD BGCOLOR=white CLASS="SolidBlack" ALIGN=CENTER>
<FONT CLASS="section">
<A HREF="myrunner/index.htm">MY 4RUNNER</A></FONT></TD>
</TR>
<!-- Pictures -->
<TR>
<TD CLASS="highlight1"><A HREF="http//www.calrockx.com/4runner/myrunner/pictures/index.htm">PICTURES</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/myrunner/pictures/current.htm">- Current</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/myrunner/pictures/old.htm">- Old</A></TD>
</TR>

<!-- Mods -->
<TR>
<TD CLASS="highlight1"><A HREF="http//www.calrockx.com/4runner/myrunner/mods/index.htm">MODIFICATIONS</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/myrunner/mods/exterior.htm">- Exterior</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/myrunner/mods/interior.htm">- Interior</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/myrunner/mods/offroad.htm">- Off-Road</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/myrunner/mods/performance.htm">- Performance</A></TD>
</TR>

<!-- Trails -->
<TR>
<TD CLASS="highlight1"><A HREF="http//www.calrockx.com/4runner/myrunner/trails/index.htm">TRAILS</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/myrunner/trails/pictures.htm">- Pictures</A></TD>
</TR>



<TR>
<TD BGCOLOR=white CLASS="SolidBlack" ALIGN=CENTER>
<FONT CLASS="section">
<A HREF="allrunners/index.htm">ALL 4RUNNERS</A></FONT></TD>
</TR>
<TR>
<TD CLASS="highlight1"><A HREF="http//www.calrockx.com/4runner/allrunners/information.htm">INFORMATION</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/allrunners/information/tech.htm">- Tech</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/allrunners/information/trails.htm">- Trails</A></TD>
</TR>
<TR>
<TD CLASS="highlight1"><A HREF="http//www.calrockx.com/4runner/allrunners/links/index.htm">LINKS</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/allrunners/links/products">- Products</A></TD>
</TR>
<TR>
<TD CLASS="highlight2"><A HREF="http//www.calrockx.com/4runner/allrunners/links/community">- Community</A></TD>
</TR>
</TABLE>










now the website that has that menu is www.calrockx.com/4runner/new

each page on it has that menu. the main index, and all pages like myrunner/index.htm, and myrunner/information/history.htm


so the plan was to on all those pages use a simple include to call the menu in. the problem was that the <A HREF> tags i used in the menu.htm only apply from the initial index perspective, and won't work in the subfolders.


so from what i understand of your posts, i need to change the <A HREF> tages to

$_SERVER['DOCUMENT_ROOT']."/includes/file.php"



is that correct? does that include all the necessary quotes and tags and <?'s ? does it replace the entire current <A HREF> tag, or just go within those quotes of the <A HREF> tag?

i kinda get what you're saying, i just don't get how to implement it.

thanks for you help, i really appreciate it

pyro
11-25-2003, 09:18 AM
Ok, my bad. I thought you were still asking how to inlcude the menu.

What you will want to do is just change you links to be absolute links, rather than relative links. Here's some examples:

<a href="http://www.php.org">PHP</a> - absolute
<a href="http://www.yoursite.com/page.php">page</a> - absolute
<a href="/page.php">page</a> - absolute

<a href="page.php">page</a> - relative (no preceding slash)
<a href="../page.php">page</a> - relative