I am trying to display code from a php file on a php file in a subfolder.
I trying to display a header and footer file on a sub-level index page.
Here is my code: Header.php:
<html>
<head>
<title>Mark VIII | Tommy Car Wash</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<base href="http://www.domain.ca/base/website/" target="_blank" />
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<body>
<div class="header">
<div class="header-content">
<div class="logo">
<a href="home.php">
<img src="images/logo.png" alt="" title=""/>
</a>
</div>
<div class="acc-cart-search">
<div class="acc-back">
<a href="#">Login</a>|<a href="#">Cart</a>
</div>
</div>
<div class="main-nav">
<nav class="nav">
<ul class="nav-list">
<li class="nav-item"><a href="store.php">Shop</a></li>
<li class="nav-item"><a href="#">Site Models</a></li>
<li class="nav-item"><a href="#">Equipment</a></li>
<li class="nav-item"><a href="#">Vacuum Systems</a></li>
<li class="nav-item"><a href="#">Detergents</a></li>
<li class="nav-item"><a href="#">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
<div class="grw-bar"></div>
</div>
Footer.php:
<div class="footer">
<div class="footer-content">
<div class="grad-bar"></div>
<div class="creds">
<img src="images/usa.jpg" alt="" title="" />
<img src="images/bbb.jpg" alt="" title="" />
<img src="images/ica.jpg" alt="" title="" />
<img src="images/40-years.jpg" alt="" title="" />
</div>
<div class="address">
<address>
<strong>Tommy Car Wash Systems</strong><br>
581 Ottawa Ave. Suite 300<br>
Holland, Mi 49423<br>
USA
</address>
</div>
<div class="media-icons">
<a href="#"><img src="images/facebook.png" alt="" title="" /></a>
<a href="#"><img src="images/twitter.png" alt="" title="" /></a>
<a href="#"><img src="images/YouTube.png" alt="" title="" /></a>
<a href="#"><img src="images/blog.png" alt="" title="" /></a>
</div>
<div class="csd">
<img src="images/csd.png" alt="" title="" />
</div>
<div class="copy">
<p>© <?php echo date("Y") ?> Tommy Car Wash Systems. All rights reserved.</p>
</div>
</div>
</div>
</body>
</html>
And the page I'm trying to display my information on index.php:
<?php require (__DIR__ . '/header.php'); ?>
<?php require (__DIR__ . '/footer.php'); ?>
The page is under the subfolder site-models
<?php include '/yoursubfolder/header.php'; ?>
If the file header.php
is in your document root:
<?php require ($_SERVER["Document Root"]. '/header.php'); ?>
If you have it in the parent directory of the present directory:
<?php require ('../header.php'); ?>
If you need to search it in the parent directory, in the parent directory of the parent directory, in the parent directory of the parent directory of the parent directory, and so on:
<?php
$file = "header.php";
do{
$file = "../".$file;
} while(!file_exists($file));
require($file);
?>