Include html / php content from another file

1

I'm working on a simple web without a framework, and this website should have a header and a footer on all pages, it's 3, the thing is I do not want to be copying that footer and that header all the time in each of the pages with which I would like to have them made in a separate file or 2 files and include them in my files to be displayed.

How could I do this?

Thank you very much.

    
asked by Pavlo B. 18.10.2016 в 09:40
source

4 answers

3

For that you have the function include. You can program a page header.php and another one like footer.php and call them on the pages you need them.

To call a file using the include function, this sentence would suffice within your php code:

<?php

//Includes es el directorio donde estaría header.php. Puedes darle el nombre que quieras
include("includes/header.php");

?>

Then in the header you write your html code. With this you will be able to reuse the pages without needing to be writing them constantly.

PHP References: link

    
answered by 18.10.2016 / 09:50
source
2

If there are only 3 copy paste the header and the footer is not so much either. But if then you are going to expand it is fine your idea of having as a master page where you always find your header and your foot.
I tell you that you have several options:
1.- You can use Adobe Muse allows you to create master pages to create the header and footer of your page.
2.- You can do this with jquery: ( link )
3.- You can also do it with php: (Full article here: link )

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head>
<title>Home page – My Website</title>
<meta http-equiv="description" content="page description" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css">@import "styles.css";</style>
</head>

<body>

<?php include("includes/header.html");?>
<?php include("includes/navigation.html");?>

This is the content of the page

<?php include("includes/footer.html");?>

</body>
</html>

I hope it serves you.

    
answered by 18.10.2016 в 09:54
0

You can try using the php include function. link

    
answered by 18.10.2016 в 09:42
0

If the application continues to grow, include will also become a problem, for example, if the user wants the menu to change places, you will have to move the include in all the files that call it. I think it is better to make a container, such as the index.php, which has the headers, footers, menus and so on, and that the main content is the include. There are many ways to achieve this, but the concept is that.

    
answered by 18.10.2016 в 18:56