Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 58,895 times

Contents

Related Categories

Simple PHP includes - The Navigation Bar

Chocobo

The Navigation Bar

I'll start off by teaching you how to create a basic site that uses a menu in tables. Run Notepad and create a file for your menu, in a table. It might look something like this:

&lttable border=0 bordercolor="black" cellspacing=0 cellpadding=0 width=780 height=100%>
&lttr>
&lttd width=100 valign="top">
&ltimg src="main.jpg">&ltbr>&ltBr>
   &lta href="index.php">News/Home<a>&ltBr>
   &lta href="index.php?page=stuff">Stuff<a>&ltBr>
   Blah&ltBr>
   Blah&ltBr>
   Blah&ltBr>
   Blah&ltBr>
   Blah&ltBr>
   Blah&ltBr>
<td>

Make sure that you do not close the table!! Now save this file as menu.php and start a new one. It'll have the code for you main page. It should look something like this:

< include("menu.php") ?>
&lttd width=580 valign=top>
<
if(!$page) {
include("http://www.hobbiton.org/~zeroone/test/news.txt");
}&ltBr>
else{
include("http://www.hobbiton.org/~zeroone/test/files/" . "$page" . ".php");
}&ltBr>
?>&ltBr>
<td>
<tr>
<table>


There are two vital things you should notice here. First, we have the < include("menu.php") ?>. This tells the computer to include the menu file. The second thing is this code:

<
if(!$page) {
include("http://www.hobbiton.org/~zeroone/test/news.txt");&ltBr>
}&ltBr>
else{
include("http://www.hobbiton.org/~zeroone/test/files/" . "$page" . ".php");
}
?>

Make sure you change the URLs to URLs on your server. This code tells the computer that if the url is something like "www.yourpage.com/index.php" then it will include the news file, in this case (since I've set it to the URL of my test site's news file).

IF, however, the URL is something like "www.yourpage.com/index.php?page=stuff" then it will change the content of the page to whatever is in the file "stuff.php". At this point, there is something I should mention. When you have links on a php page, they will be something like "www.yourpage.com/index.php?whatever=pagename" instead of something like "www.yourpage.com/pagename.php". This is because the web browser is actually displaying the index file, but it's including content from another file on the index file. The "whatever=pagename" tells the computer that the variable "whatever" is set to the name of the page, "pagename" in this case. That variable tells what page's content should be displayed, using the code above.

Uhm... I dunno why I'm typing this, cuz nobody is gonna read it probably, but anyway... I am (guess my age!! haha... 14) years old and I like programming, web design, and graphic design. I'm pursuing a career in game programming. I like basketball, volleyball, skiing, snowboarding, and skateboarding. My favorite pro skater: [b]Jamie Thomas!![/b] Well... I guess that about covers it. Oh yeah... I love to play video games, I'm a Final Fantasy fanatic, I have FF7-9 and FFT, gonna get FF10... I also like the Tony Hawk's Pro Skater series. Gameboy Advance rules! :p

All content in this tutorial was created by the author, Jamie Lindgren, and may not be reproduced without the author's permission. To contact the author, please send an e-mail to wipeoutgc@hotmail.com

Comments

  • php includes

    Posted by AR on 05 Sep 2004

    Try using this:

    include $_SERVER[DOCUMENT_ROOT]."/common/yourfile.php";

    This should do it.

    [url="http://www.summitcolorado.com"]Breckenridge[/url] Guy!

  • include example with half instructions incomplete

    Posted by altimastr on 03 Sep 2004

    [email="altimastr@yahoo.com"]email me[/email] , a your instructions as follows just gives you a name for the first page when creating your example for the first half of the code but what about the se...

  • What about caching?

    Posted by shizuka on 12 Sep 2003

    I gave the "corrected" code a try, but I'm using Javascript rollovers in the menu bar and now the buttons pause before loading, even though the script preloads them--and not only that, but it does tha...

  • Security Not an Issue?

    Posted by PHPeep on 10 Jul 2003

    If security is not an issue, what is wrong with simply making you header, footer, sidebar content as .txt includes for example and just use the where you want them to show up in your .php fi...

  • Posted by fame on 09 Apr 2003

    zidane,

    your reply was so helpful, that i've built a site around it and registered just to thank you.

    so... thank you. ;)



    fame