Forum Moderators: phranque

Message Too Old, No Replies

What is the best way to include pages (with one header and footer)?

         

joliett89

6:15 pm on Feb 8, 2012 (gmt 0)



I have header.php, footer.php and index.php files (I was trying to use index.html but that does not work with XAMPP). What is the best way to go about that? Would I just make all files .php?

header.php
index.php (home page)
about.php
services.php
resources.php
contanct.php
footer.php

...and just keep including whatever I need?

index.php file:

<?php include("header.php)"; include("about.php"); include("footer.php"); ?>

Thank you.

phranque

9:07 pm on Feb 8, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can do this using SSI (Server Side Includes)

g1smd

9:24 pm on Feb 8, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can use SSI but there's a lot more power to be had by using PHP.

Don't forget that page.php is just the name of the file on the server hard drive. It doesn't have to be accessed that way as a URL. You can choose whatever URL you want to use for accessing that file, and connect the URL request to the server filename by using an internal rewrite.

lucy24

11:52 pm on Feb 8, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you can do this using SSI (Server Side Includes)

But that's only for static text, right? You can't pass it a variable and say for example "Construct a set of links using this basic HTML, but make item x look different, and then add it to the page."

rocknbil

4:39 pm on Feb 9, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do that with SSI. :-) A typical example might be setting class "current" on whatever page you're on. You can also "include" a script or executable, be it perl, php, anything. But if the site is PHP based, a php solution makes more sense.