1

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>

'
?>
12
  • So the php you want to be echoed is not displaying or your entire page is now blank? Commented May 19, 2014 at 3:18
  • 1
    Both header and footer are missing the semicolon after the echo. FWIW you appear to be importing the footer into the top and bottom of your page. Commented May 19, 2014 at 3:18
  • 1
    @MikeW I'm not sure the semi-colon is required. I often use <?= $foo ?> without a semi-colon Commented May 19, 2014 at 3:19
  • 2
    @MikeW Just tried it locally. You must be doing something else on codepad because it works fine for me ~ codepad.org/UapisczT Commented May 19, 2014 at 3:24
  • 1
    BINGO - There you go. You can't access those files that way. PHP needs to be installed and properly configured (if it's not installed, which I tend to think it's not), otherwise they won't be parsed properly. PHPStorm is an editor, not a parser/browser. Commented May 19, 2014 at 3:47

2 Answers 2

1

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>
     ';
        ?>
Sign up to request clarification or add additional context in comments.

4 Comments

I'm not entirely sure they're required in this context. The ?> delimiter is usually enough to signify end-of-statement
Awesome thanks eddie, but it's still not loading. I'm using PHPstorm and i go to chrome, it opens in the browser, but nothing is displayed on the page and there is the loading animation in the tab.
@av17, when you remove the include 'footer.php' and 'header.php' from your index, does your page load?
Thanks Eddie (: You fixed it. Thanks for being my first upvote
1

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 -->

1 Comment

Perhaps this is a comment instead?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.