Reputation: 105
I'm learning PHP and right now i'm learning how to add files.
However,
I'm having trouble importing for example, my header.php into my index.php file.
My browser is stuck loading, and nothing is displayed.
I have two php files; a footer.php and a header.php that i'm trying to include into a index.php
Here's my code for Index.php
<html>
<head>
<title><?php echo $page['title'];?></title>
</head>
<body>
<div class="headerr">
<?php
$page = array();
include 'footer.php';
?>
</div>
<div>
<h1>
Hola
</h1>
<article>
Nulla mauris odio, vehicula in, condimentum sit amet, tempus id, metus. Donec at nisi sit amet felis blandit posuere. Aliquam erat volutpat. Cras lobortis orci in quam porttitor cursus. Aenean dignissim. Curabitur facilisis sem at nisi laoreet placerat. Duis sed ipsum ac nibh mattis feugiat. Proin sed purus. Vivamus lectus ipsum, rhoncus sed, scelerisque sit amet, ultrices in, dolor. Aliquam vel magna non nunc ornare bibendum. Sed libero. Maecenas at est. Vivamus ornare, felis et luctus dapibus, lacus leo convallis diam, eget dapibus augue arcu eget arcu.
</article>
</div>
<div class="footterr">
<?php
include 'footer.php';
?>
</div>
</body>
</html>
header.php
<?php echo '
<!-- top menu bar -->
<table width="90%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><a href="#">Home</a></td>
<td><a href="#">Site Map</a></td>
<td><a href="#">Search</a></td>
<td><a href="#">Help</a></td>
</tr>
</table>
<!-- header ends -->
' ?>
footer.php
<?php echo'
<!-- footer begins -->
<br />
<center>Your usage of this site is subject to its published <a href="tac.html">terms and conditions</a>. Data is copyright Big Company Inc, 1995-<?php echo date("Y", mktime()); ?></center>
'
?>
Upvotes: 1
Views: 72
Reputation: 3691
You don't really need to use echo on footer.php and header.php. Your index.php looks fine to me.
footer.php
<!-- footer begins -->
<br />
<center>Your usage of this site is subject to its published <a href="tac.html">terms and conditions</a>. Data is copyright Big Company Inc, 1995-<?php echo date("Y", mktime()); ?></center>
header.php
<!-- top menu bar -->
<table width="90%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><a href="#">Home</a></td>
<td><a href="#">Site Map</a></td>
<td><a href="#">Search</a></td>
<td><a href="#">Help</a></td>
</tr>
</table>
<!-- header ends -->
Upvotes: 1
Reputation: 26854
you forgot semi colon on your header and footer. and also you dont need to re open the php in footer for time function (you only need to append it to the text)
header:
<?php echo '
<!-- top menu bar -->
<table width="90%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td><a href="#">Home</a></td>
<td><a href="#">Site Map</a></td>
<td><a href="#">Search</a></td>
<td><a href="#">Help</a></td>
</tr>
</table>
<!-- header ends -->
'; ?>
footer:
<?php echo'
<!-- footer begins -->
<br />
<center>Your usage of this site is subject to its published <a href="tac.html">terms and conditions</a>. Data is copyright Big Company Inc, 1995-' . date("Y", mktime()) . '
</center>
';
?>
Upvotes: 1