Jump to content

menu.php


CNT

Recommended Posts

menu.php

<ul id="navbar"><li><a href="index.htm">Home</a></li><li><a href="#">Something</a></li><li><a href="#">Contact me</a></li></ul>

index.html

etc...etc...</head><body><?php include($DOCUMENT_ROOT . "menu.php"); ?></body></html>

I am starting all over, since I can't get my menu to work right. So, while starting over, I might as well attempt to do the PHP page, so it's all in one place and I just add one line in every html page. Once this works, then I will start the CSS page. Is there anything wrong with above code? Both files are in same root directory (or should the PHP file be in a PHP folder or not?).Chuck

Link to comment
Share on other sites

Most servers are not configured by default to execute php code in a file without a .php extension.It is common for include files to be kept in a subdirectory, but this is not a requirement, especially if your project is small.$DOCUMENT_ROOT only exists if register_globals is turned on. Using register_globals is seriously deprecated since it can open security leaks. The same information can be found in $_SERVER['DOCUMENT_ROOT'] .But I don't see why you'd need it in this example. If menu.php is in the same directory as the index document, you shouldn't need extra path information. Even if you put it in a subdirectory, all you'd need to identify it would be subdir/menu.php

Link to comment
Share on other sites

index.html
etc...etc...</head><body><?php include("menu.php"); ?></body></html>

Is this correct now? I did that and it doesn't work. What you mean by:
Most servers are not configured by default to execute php code in a file without a .php extension.
The menu.php file does have the .php extension?Chuck
Link to comment
Share on other sites

but the undex.html does not, you have php code in html page.
your index is html index should be php extension..I believe dsonesuk is saying..if I understand him correctly..
Link to comment
Share on other sites

That's correct. The file that is executing is the one called by the browser. So if the index file contains php code, it should be index.php . Included files can have almost any extension. I often see .inc being used so the developer can remember what it's being used for.

Link to comment
Share on other sites

as diedre's dad said include file can be also the other extension (eg .inc) to be get recongnised but you have to make sure that your server is set up to parse that extension as a php file otherwise it will shown as plaint text which is not desireable.

Link to comment
Share on other sites

as diedre's dad said include file can be also the other extension (eg .inc) to be get recongnised but you have to make sure that your server is set up to parse that extension as a php file otherwise it will shown as plaint text which is not desireable.
1) So, doing "index.htm" is not allowed?2) I am running my webpages within my laptop. I use VS2008 as my editor (and SQL Server 2008). When I debug it, it runs as a webhost within my laptop, is it possible that I need to change the IIS to accecpt PHP?3) I hope what I am doing is common? I mean create a nav menu in one page and only use one line on every HTML page. The "normal" way would be having all the "li" and menu stuff on every HTML page and when making one tiny change, I would have to copy/paste that onto every HTML page. According to my study, only way to do this is PHP. correct?On my other website I designed, I used the following and it works. Is the following something I need to add for the menu?
<form method="post" action="submit_register.php">

What I want to accomplish is to have a (one line) horizontal menu on top and make it stay there. When scrolling down, I want the horizontal menu remain visible. The dropdown submenu will drop over naturally. I will not use frame for that, but the idea is like a frame thing. That I don't know how to do yet, but thats on my goal list. Amazing that I am only trying to do simple things first (one menu page and php), it's not working already?Chuck

Link to comment
Share on other sites

1) allowed if your server is set up to parse .htm as php file.genaraly by default it wont parse .htm file and will show it as plain text html. For now you may not want to mess with that instead of use the sugestion of dsonusk.changing the extension to index.php should work fine and will do what you wanted.including the menu is good rather than using frames.

What I want to accomplish is to have a (one line) horizontal menu on top and make it stay there. When scrolling down, I want the horizontal menu remain visible. The dropdown submenu will drop over naturally. I will not use frame for that, but the idea is like a frame thing. That I don't know how to do yet, but thats on my goal list. Amazing that I am only trying to do simple things first (one menu page and php), it's not working already?
when you include a file it will work something like just copy paste. the included file will be added as it is. You can set a style for nav bar which will take effect on all page you have included navpage.php. to make it sticky on the page you can make the position:fixed to nav div.
Link to comment
Share on other sites

So, I would have to change the page to index.php, and also every other page with .php for in order to get the navpage.php to work, like the following?index.phpevents.phphistory.phpnavpage.phpcontactus.phpMay I ask what you guys do concerning navigation? I don't mind copy/paste the "whole" menu (from div to div) everytime I change something (like a spelling, change of wording, new page, or whatever). But there has to be a better way. Google doesn't provide much on new way of navigation menu page (other than php, in which where I got this idea so far). W3S doesn't have it either? Is this a new concept? Tell me suggested methods.CSS is only for position, fonts, style, etc...Chuck

Link to comment
Share on other sites

You are on the right track. For common elements like menus and such, it is extremely common to save that html as a separate file and include it as you suggest.I typically keep the CSS that styles the included items in unique files also. So if I plan to include menu.php, I will link to menu.css also.Here's a small tutorial. It describes exactly what you're talking about.---Another common strategy is essentially the reverse of this idea. Construct a "shell document" that contains all the elements common to all your documents, including a blank area where content will be included. CMS and Blogs do this sort of thing with what they call templates. URLs to a particular "document" generally point to the template and include a query string. The query tells the template document which content document to include in the content area, so you end up with more PHP but only one include statement. The technique allows an entire site to have an extremely uniform appearance, very suitable to corporate and educational environments.(FWIW, ugly query strings can be disguised using a technique called URL rewriting, but that's another lesson.)

Link to comment
Share on other sites

it is extremely common to save that html as a separate file
I am not following this... Keep what file as what HTML ?I forgot something... correct me on this one:index.phpevents.phphistory.phpnavpage.phpstyle.csscontactus.phpThe only page that will not have .php is the .css page, correct?I am asking those questions... I haven't had time in past few days to try these hands-on.Chuck
Link to comment
Share on other sites

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>	<title>Hey</title></head><body><?php include("menu.php"); ?></body></html>

menu.php

<li><a href="index.php">Home</a></li><li><a href="#">Something</a></li><li><a href="#">History</a></li><li><a href="#">Contact me</a></li>

Above is the only two page I created so far. I am just trying to run it to actaully see it "working", but it isn't working? I am using Visual Studio 2008 and SQL Server 2008. I test my web by running Debug. Is there something I need to add or change in the above code?

Link to comment
Share on other sites

i am not sure about visual studio. You have to install a web server like apache and php. there is package(WAMP for windows, LAMP for linux MAMP for mac and XAMPP) for web server php mysql and other things. you may want to download one of them and install it. to run a php file locally you need one of those.your code looks well and should work once you set up your local server.

Link to comment
Share on other sites

Yeah, assuming your server plays nice, the way you've structured your two files is almost the normal pattern.Be sure to wrap your list items in <ul> or <ol> tags.

Link to comment
Share on other sites

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Something</title></head><body><ul><li><a href="index.php">Home</a></li><li><a href="#">Something</a></li><li><a href="#">History</a></li><li><a href="#">Contact me</a></li></ul></body></html>

When I run this above alone (as index.php), it works. Now, when I try the below, it does NOT work, what is the difference or missing codes? The index.php and menu.php are in the same directory. Keep in mind that this is everything I am testing, so don't assume I have some codes in else where...index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Something</title></head><body><?php include("menu.php"); ?></body></html>

menu.php

<ul><li><a href="index.php">Home</a></li><li><a href="#">Something</a></li><li><a href="#">History</a></li><li><a href="#">Contact me</a></li></ul>

Lastly, is it preferred to use ".inc" ? So, basically, it goes like this:index.phpmenu.incstyle.csssomething.phphistory.phpetc...Forgive me if this is beginning to be redundant. BTW, if I could run my other website with php page and works on my VS2008, then it should work with this test? In my other working website, I have the following, yet when I use it on this test page, it still not work:menu.php

<?phpblahblah?>

Chuck

Link to comment
Share on other sites

did you installed the server first?

Link to comment
Share on other sites

did you installed the server first?
When I debug the website, I run it on my localhost browser, so I guess the "server" is installed? I have VS 2008 installed. Also, SQL Server is installed (but that would only be for SQL language, not a "server" in spite of the title name, correct?). I have .NET thing all updated.Is there a way to tell if I have a "server" installed? What would I be looking for? Again, I only have VS2008 (full retail version, ordered directly from MS), with SQL with it.Chuck
Link to comment
Share on other sites

When I debug the website, I run it on my localhost browser, so I guess the "server" is installed? I have VS 2008 installed. Also, SQL Server is installed (but that would only be for SQL language, not a "server" in spite of the title name, correct?). I have .NET thing all updated.Is there a way to tell if I have a "server" installed? What would I be looking for? Again, I only have VS2008 (full retail version, ordered directly from MS), with SQL with it.
You need a web server to run PHP. SQL Server is a server but it is a database server, not a web server. You could download and install WAMP to run your PHP files.
Link to comment
Share on other sites

put that in a page and save it as and put it in localhost document root. then go to your browser and enter localhost/yourpagename.php. is it showing you anything?..it should show you the information about you installed php. If it is showing then your php and server is ready to use.

<?phpphpinfo();?>

You dont need .NET framework here or visual studio to work with php. i am not sure there is any option in it for php. but genaraly people use some text editor to write codes like notepad, or a better option notepad ++ or netbeans..etc

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...