# Solved: Include Footer php syntax



## skyhigh007 (Jun 17, 2004)

Hi

Is it a good practice to have the following code save it as footer.php and include it in the index.php use Include function?

```
<div id="footer">
    <ul>
      <li><a href="index.php">Home</a></li>
      <li><a href="shipping.php">Shipping</a></li> 
      <li><a href="privacy.php">Privacy Policy</a></li>
      <li><a href="contact.php">Contact Us </a></li>
      <li><a href="news.php">News</a></li>
      <li><a href="termsofuse.php">Terms of Use</a></li>
    </ul>
      <div id="subFooter">
        <p class="copyright">Copyright &copy; 2007 my company, inc.  All Rights Reserved </p>
      </div> 
  </div>
```


----------



## TheRobatron (Oct 25, 2007)

Yeah, that's what a lot of people do to make it easier to maintain their sites.


----------



## Eriksrocks (Aug 7, 2005)

If you're asking for the syntax (confused between your title and the contents of your post) then it would be like this:


```
include( "footer.php" );
```
I actually recommend using the require function because it will stop the execution of the page if the file is not found, which is recommended.  So it would then be like:


```
require( "footer.php" );
```
And yes, it's a good practice because then you don't have to change the footers individually if you add something new, change a link, etc.


----------



## skyhigh007 (Jun 17, 2004)

Thank you very much! DO I need to add <?php ?> for the entire code?


----------



## Eriksrocks (Aug 7, 2005)

skyhigh007 said:


> Thank you very much! DO I need to add <?php ?> for the entire code?


Just for the PHP code, not the entire page.  So it would be like 

```
<?php
require( "footer.php" );  
?>
```
Wherever you want to include the footer.


----------



## skyhigh007 (Jun 17, 2004)

I meant put it around the entire footer code


----------



## Eriksrocks (Aug 7, 2005)

If I understand you right, no. 

Let's assume all that footer.php contains is:

```
[LIST]
      [*][URL=index.php]Home[/URL]
      [*][URL=shipping.php]Shipping[/URL] 
      [*][URL=privacy.php]Privacy Policy[/URL]
      [*][URL=contact.php]Contact Us [/URL]
      [*][URL=news.php]News[/URL]
      [*][URL=termsofuse.php]Terms of Use[/URL]
    [/LIST]

Copyright © 2007 my company, inc.  All Rights Reserved
```
Then wherever you wanted to include that on other pages you would simply put:

```
<?php
require( "footer.php" );  
?>
```
Does that make sense?


----------



## TheRobatron (Oct 25, 2007)

Eriksrocks said:


> I actually recommend using the require function because it will stop the execution of the page if the file is not found, which is recommended.


Surely it would be better to not stop the execution of a page, and just not display anything? This way, if there is an error in the code, the viewers of the site won't notice it.


----------



## Eriksrocks (Aug 7, 2005)

TheRobatron said:


> Surely it would be better to not stop the execution of a page, and just not display anything? This way, if there is an error in the code, the viewers of the site won't notice it.


They might not notice the footer gone, but I think they will notice if the header or other main parts of the site are missing. 
[WEBQUOTE="http://www.tizag.com/phpT/require.php"]We recommend that you use require instead of include because your scripts should not be executing if necessary files are missing or misnamed.[/WEBQUOTE]
For a footer, it's not such a big deal but it's a good practice that you should get in the habit of doing.


----------



## TheRobatron (Oct 25, 2007)

I see what you mean


----------



## skyhigh007 (Jun 17, 2004)

What i meant was put the <?php ?> inside the footer.php. So require is the standard way to go right instead of include?


----------



## Mudley (Apr 7, 2008)

include is the standard way, unless the included file is detrimental to the processing of further code completion.

for something like a footer, I would use an include, not a require.


----------



## Eriksrocks (Aug 7, 2005)

skyhigh007 said:


> What i meant was put the <?php ?> inside the footer.php. So require is the standard way to go right instead of include?


No you should *not* put the <?php ?> inside of footer.php. Actually, footer.php doesn't need to have a .php extension, it could be footer.html or footer.txt even.

Require isn't the "standard" way, nor is include, but using require is a good programming practice. Like I said before, for a footer it doesn't really matter, so use whichever one you want.


----------



## TheRobatron (Oct 25, 2007)

All the include/require function is doing, is taking the output of a file and placing it in itself. For what you're doing, you don't need the PHP tags, but for other things you may want to include PHP files that process information, so anything that would be sent to the browser by directly viewing the included file, is outputted in the main file.

That's probably not very well explained, so for the answer to your question see the post above, but hopefully it'll help if you ever want to include PHP files.


----------



## skyhigh007 (Jun 17, 2004)

Thank you very much guys!


----------

