# [SOLVED] How do I make index.php auto load home.php?



## ggormsen (Nov 1, 2008)

Hey all,
I have the site setup on my testing server. www.gcgcg.com/testing

I have a bunch of pages that I need to load into the content box (all other areas are static)


My index.php page:

```
<html>
<head>
<title>Title</title>
</head>

<body bgcolor="#F47A26">
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td><?php include("header.php"); ?></td><td rowspan="4" valign="top"><?php include("sidebar.php"); ?></td></tr>
<tr><td><?php include("main.php"); ?></td></tr>
<tr><td><?php include("footer.php"); ?></td></tr>
</table>
</body>
</html>
```
My main.php (content) page:

```
<!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><link href="styles/main.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" class="st2">
  <tr>
    <td><?php
switch($_GET['page']){
case 1:
include_once('home.php');
break;
case 2:
include_once('whatwedo.php');
break;
case 3:
include_once('theopportunity.php');
break;
default:
include_once('portfolio.php');
break;
include_once('ourteam.php');
break;
}
?></td>
  </tr>
</table>
</body>
</html>
```
Basically, I am attempting to create the page so that the sidebar, the footer, and the header all are static, while the content page changes.

What I am having trouble with right now is getting the content page to load any content.

It is supposed to auto-load home.php, then when you click on a link in the header, or on one of the image boxes on home.php, it should load that content.

Note: frames and iframes are not an option, it has to be php, javascript, or ajax.

Thank you all for your time.


----------



## Laxer (Dec 28, 2010)

*Re: How do I make index.php auto load home.php?*

I find it easier to include the 3 pages (header,footer,navigation) into the page. As apposed to including a bunch of content into one page...

To do so open up one of the content pages and place the includes above and below the content(Depends on your setup).

Alternatively you could keep track of information then append it onto an include so its gets loaded.

An example would be in the broweser(GET) url.com/index.php?p=12

or VIA post, where its stored on the server.... (Post cannot be linked to)
If you can provide me the source of the index page I can instruct you on how to set it up :grin:


----------



## ggormsen (Nov 1, 2008)

*Re: How do I make index.php auto load home.php?*

The source of the index page is included in the original post.

What I think you are saying is that you would hard code the content into the table, then just reference the sidebar, footer, and header into each page, right? I can definitely do that, but I was really trying to steer away from that. I would like index to be the only real page, and everything load kinda like site.com/index.php?page=2

I've seen it done by Wordpress, and many other sites, so I know it is possible.

Thank you so much!


----------



## Laxer (Dec 28, 2010)

*Re: How do I make index.php auto load home.php?*

Its pretty easily done... but all of those sites store the information in a database not a separate page...

Sorry I didn't see the first code box...

What I would do if you want to keep it how you are thinking:


```
<!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><link href="styles/main.css" rel="stylesheet" type="text/css" />
</head>

<body bgcolor="#F47A26">
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td><?php include("header.php"); ?></td><td rowspan="4" valign="top"><?php include("sidebar.php"); ?></td></tr>
<tr><td>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" class="st2">
  <tr>
    <td><?php
switch($_GET['page']){
case 1:
include_once('home.php');
break;
case 2:
include_once('whatwedo.php');
break;
case 3:
include_once('theopportunity.php');
break;
default:
include_once('portfolio.php');
break;
include_once('ourteam.php');
break;
}
?></td>
  </tr>
</table>
</td></tr>
<tr><td><?php include("footer.php"); ?></td></tr>
</table>
</body>
</html>
```
AKA, just remove main.php...

declaring the <head> and body twice will cause issues...

If you want to keep the main page individually do something like this:

```
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" class="st2">
  <tr>
    <td><?php
switch($_GET['page']){
case 1:
include_once('home.php');
break;
case 2:
include_once('whatwedo.php');
break;
case 3:
include_once('theopportunity.php');
break;
default:
include_once('portfolio.php');
break;
include_once('ourteam.php');
break;
}
?></td>
  </tr>
</table>
```
Don't worry about the html/head/body as it is included in the index.php


----------



## liamm (Jan 6, 2012)

*Re: How do I make index.php auto load home.php?*

ggormsen,

Hello, in your switch set default case to include your homepage.


```
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" class="st2">
  <tr>
    <td><?php
switch($_GET['page']){
case 1:
include_once('home.php');
break;
case 2:
include_once('whatwedo.php');
break;
case 3:
include_once('theopportunity.php');
break;
include_once('portfolio.php');
break;
include_once('ourteam.php');
break;
default:
include_once('home.php');

}
?></td>
  </tr>
</table>
```


----------



## ggormsen (Nov 1, 2008)

*Re: How do I make index.php auto load home.php?*

That worked wonderfully! Thank you lliam for you update on the code. The default worked great.
Thank you Laxer for everything!

This has really been a fun learning experience for me while learning PHP.

Thank you!


----------



## Laxer (Dec 28, 2010)

No problem,

Great work Liamm, didn't even notice the missing default case :thumb:
Dont forget to add the other cases...


```
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" class="st2"> 
  <tr> 
    <td><?php 
switch($_GET['page']){ 
case 1: 
include_once('home.php'); 
break; 
case 2: 
include_once('whatwedo.php'); 
break; 
case 3: 
include_once('theopportunity.php'); 
break;
case 4:
include_once('portfolio.php'); 
break;
case 5: 
include_once('ourteam.php'); 
break; 
default: 
include_once('home.php'); 
} 
?></td> 
  </tr> 
</table>
```


----------

