Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include html pages in a php file

Tags:

html

php

I would like to create a template using html and css so I created the following template.html file:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Application</title>
<link href="CSS/layout.css" rel="stylesheet" />
<script src=""></script>
</head>

<body>
<div class="wrapper">
    <div class="header">
        <!--<div class="header_left"></div>
        <div class="header_right"> -->
            <h3>Application</h3>
            <h4>****  Project ****</h4>

    </div>
    <div class="navbar">
        <ul class="mainnavbar">
            <li><a href="#">Home</a></li>
            <li><a href="login.html">About</a></li>
            <li><a href="#">Description</a></li>
            <li><a href="#">Contact Me</a></li>
        </ul>
    </div>
    <div class="mainbody">
        <div class="leftcol">
            <div class="left_navbar">
                <ul class="left_inner">
                    <li><a href="#">Login</a></li>
                    <li><a href="#">About</a></li>
                    <li><a href="#">Description</a></li>
                    <li><a href="#">Contact me</a></li>
                </ul>
            </div>
        </div>
        <div class="midcol">
            Center
        </div>
        <div class="rightcol">
            Right Column
        </div>
    </div>
    <div class="footer">Designed By <a href="">Me</a></div>
</div>
</body>
</html>

Because I want to create a dynamic website I want to separate this template.html into index.php, header.php, navbar.php, home.php and footer.php. So I did the following:

index.php

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

header.html

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Application</title>
<link href="CSS/layout.css" rel="stylesheet" />
<script src=""></script>
</head>
<body>
<div class="wrapper">
    <div class="header">
        <!--<div class="header_left"></div>
        <div class="header_right"> -->
        <h3>Application</h3>
        <h4>****Project ****</h4>
    </div>

navbar.html

<div class="navbar">
<ul class="mainnavbar">
    <li><a href="#">Home</a></li>
    <li><a href="login.html">About</a></li>
    <li><a href="#">Description</a></li>
    <li><a href="#">Contact Me</a></li>
</ul>
</div>

home.html

<div class="mainbody">
<div class="leftcol">
    <div class="left_navbar">
        <ul class="left_inner">
            <li><a href="#">Login</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Description</a></li>
            <li><a href="#">Contact me</a></li>
        </ul>
    </div>
</div>
<div class="midcol">
    Center
</div>
<div class="rightcol">
    Right Column
</div>
</div>

footer.html

<div class="footer">Designed By <a href="">me</a></div>
</div>
</body>
</html>

I have these files in a folder called includes. I just separated the file template.html in 4 html files and then called them from index.php, but I just get a white page when I run index.php in the browsers. Is there something missing?

like image 522
dali1985 Avatar asked Apr 19 '26 10:04

dali1985


1 Answers

Your code (syntax and idea with including html) is fine. That should work.

You have to search for problems somewhere else.

Maybe you have a problem with:

  • web server configuration (virtual hosts, directories etc.)
  • wrong url / wrong server (refreshing some web server url, but you work on local XAMPP)
  • file permissions (however apache normally should report error in that case)

Looking at web server error logs may help.

like image 144
Kamil Avatar answered Apr 22 '26 01:04

Kamil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!