Simple PHP includes

Page 2 of 3
  1. Introduction
  2. The Navigation Bar
  3. Conclusion

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.

You might also like...

Comments

About the author

Jamie Lindgren United States

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 ...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson