Jump to content

Have require() question


SmokingMan

Recommended Posts

Let me preface this by stating I know nothing about PHP. I have a navigation menu I want to include in every page on my site. Instead of writing the code in every page, I was told I could use PHP to call the file from the .html document I want the menu to be in. So here's the problem.I have the calling document "index.html" calling the seperate menu file "navmenu.html". In "index.html I have the code:

<div class="nav"><?php require("navmenu.html"); ?></div>

Both files are in the same directory, but the menu does not show up in the "index.html" document. The hosting server does support PHP 5. What am I missing here, why doesn't the menu show up?

Link to comment
Share on other sites

Make sure any page that uses php in it has a .php extention. Your code looks about right though.
So this would rename my index.html file to index.php? Would that still enable people to access my site? And would that mean all pages would need the .php extension since I want this menu on every page?
Use include ("navmenu.html") instead.
Would I use this format "<!--#include file="navmenu.html" -->" along with an ".htaccess" file? I'm not clear on what an ".htaccess" file is and where it goes though. I just remember reading that when I was looking into how to do this.I told you I'm out of my league on this. I'm comfortable with CSS & XHTML, but not PHP...yet.
Link to comment
Share on other sites

You could also just configure the server to send html files to the PHP engine, but that would slow down response times slightly for html pages. But you wouldn't have to rename anything.You can also use:include()include_once()require()require_once()Depending on what your requirements are (no pun intended).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...