Click to See Complete Forum and Search --> : nagivation


mabgirl
07-15-2006, 10:09 AM
I am currently doing websites with the same navigation bar on the left. is there any way I can make it such that everytime I update the navigation bar on one of the pages, the other bars on the other pages also updates?

I have been trying to repaste the same codes into the different pages whenever I add a new link to my navigation bar, and it is driving me crazy!

Charles
07-15-2006, 01:09 PM
Does your server support SSI or PHP?

Albatross
07-15-2006, 04:58 PM
Using server side includes or a server-side programming language is the best way to go. Granted, you can use client-side scripting (read: JavaScript) but that presents its own issues, like if the user agent (not just traditional browsers anymore) doesn't support the language or if the end user has it turned off for whatever reason.

swachtma
07-16-2006, 03:26 PM
You'll need some server side code to pull this off. SSI is the easiest way to do this I think although any servside language could pull it off. What you'll want to do is move your navigation bar into its own file and give it a name something.html.

once you've done that the code would be for example in PHP:
<?php
include('path to your file');
?>

or in SSI:

<!--#include file="path to your file" -->
this will only work if the file you are including is in the same directory as the file containing this code or a subdirectory (no using ../ basicly)

OR

<!--#include virtual="path to your file from the ROOT of your server" -->
This will let you call a file that is anywhere on your server but you must always begin from the root directory

Albatross
07-16-2006, 08:54 PM
Actually, if you're going to use PHP, use this format; that way if you move the include file, it won't break the path to the file (hopefully, anyway).

<?php include ($DOCUMENT_ROOT . "/path/to/filename.inc"); ?>

"/path/to/filename.inc" is just the path to the file. One common way to do this is to type "/includes/menu.inc" with "menu.inc" containing the raw HTML (or even PHP code) that will be interpreted by the PHP parser. This is usually a safe way to handle multiple pages.

The main exception is if you have sensitive information (like database login information) that you cannot let anyone get to. That type of information needs to be placed OUTSIDE of your Web root. (on Red Hat distributions running Apache, your root folder will usually be "public_html") So, on a Red Hat Linux server, you'll want to have the includes folder ABOVE the public_html folder.

mabgirl
07-17-2006, 12:54 AM
So if I paste

"<?php include ($DOCUMENT_ROOT . "/path/to/filename.inc"); ?>"

into my html codes where the links html are, the codes in that particular file will appear automatically on my webpage?

thanks everyone, by the way, for the prompt reply!

Albatross
07-17-2006, 12:57 AM
You'll have to save the files with the .php extension, and change the path name to reflect the actual location of the file, but yeah, you got the idea.

Note that Apache does allow you to edit the server settings to parse .html files as .php files, but that is a technical subject, and not for the faint of heart (well, not for the sysadmin's heart anyway).

swachtma
07-17-2006, 02:30 AM
You shouldn't need to use the DOCUMENT_ROOT variable, so long as you use a relative link path and not an absolute your path shouldn't break during a move unless the move changes your folder structure. That my understanding anyway, maye Albatross knows something I don't.

You can also begin your URL path with a "/" to start your relative path from the document root.

Albatross
07-17-2006, 02:57 AM
DOCUMENT_ROOT will be of immense help if your site has a directory structure. I found this out the hard way.

mabgirl
08-15-2006, 08:53 AM
hmm do i need to add anything else except for that line

"<?php include ($DOCUMENT_ROOT . "/path/to/filename.inc"); ?>" ???

because it didnt work :(

and for my links html codes, how do i save it as an .inc file? I saved it in notepad and added .inc at the back. do you do it that way?

if my links codes file is in the same directory as the website itself, do i need to add a "/" in front of my filename?

as you can see, i am really a beginner in this. any help will be appreciated!!!

ray326
08-15-2006, 01:24 PM
Question #1 is whether your server actually supports PHP or not.

mabgirl
08-16-2006, 08:30 AM
hmm how do i check?

and one more thing, i don't know how to save files as php files.

Charles
08-16-2006, 08:39 AM
It depends upon the way things are set up at the server but typically you just save a text file with a ".php" at the end of its name. Save the following as "info.php" and give it a try:<?php phpinfo(); ?>

Albatross
08-16-2006, 04:16 PM
To check to see if PHP is enabled (chances are it is if you're using anything remotely resembling a commercial-grade Web server), open up Notepad, type the following and save it as php_info.php (same way you save it as a .html file, but replace .html with .php when you type in the file extension--works the same way with .inc files)

<?php phpinfo(); ?>


Then upload to your account. If you see <?php phpinfo(); ?> then you cannot use PHP. If you see a LONG table of information, then it's running. Easy as cake.

As for the include files, replace the file path part of

<?php include ($DOCUMENT_ROOT . "/path/to/filename.inc"); ?>

with the actual path to your includes folder. Here's an example:

<?php include ($DOCUMENT_ROOT . "/includes/menu.inc"); ?>

Hope that helps.

mabgirl
08-17-2006, 08:30 AM
when you save it as something.php does it show up as a notepad file? mine does, and Im not sure it is supposed to be so.

I did what Albatross instructed me to and gah, only <?php phpinfo(); ?> appeared. so that means that my server does not support php?

but when I saved a file as links.php and opened it, it appears as a webpage.