0

So in working with my website, I am trying to use .php files for my header and my footer to make the code infinitely easier to work with, but I am running into a wall. Here is my code on my index.html page:

<!DOCTYPE html>
<html>
<?php include 'header.php';?>

And it was by going through several questions here on stack and other places that I got that syntax, but when I try and view my index.html page, nothing shows up in the header, it just goes straight for my <body>. Here is what my header.php looks like:

    <?php
    <header>
    <figure>
        <img src="the-logo.png" alt="this is just a test">
</figure>
    </header>
    ?>

As you can see, I'm just testing things out. What could I do to fix this?

Adam McGurk
  • 186
  • 1
  • 19
  • 54
  • 1
    Rename your `index.html` to `index.php`. Without changes to config, Apache can't parse PHP inside HTML files. – junkfoodjunkie Nov 27 '16 at 02:15
  • 1
    That's because `.html` files aren't processed by the PHP interpreter. So the PHP code never gets processed. Since HTML doesn't recognise the PHP code either, it simply displays it as plain text. You need to save it as `index.php` instead. – icecub Nov 27 '16 at 02:15
  • I changed it from index.html to index.php and now I can't even see my index page. It doesn't return an error message or anything, just a blank page. – Adam McGurk Nov 27 '16 at 02:22
  • @junkfoodjunkie Ye sorry, I read your comment a bit fast. My mistake. Already removed my comment :) – icecub Nov 27 '16 at 02:23
  • Renaming from `index.html` to `index.php` should have no effect whatsoever, unless you have something in that file that breaks PHP. Try removing the calls you have to include the header and footer, just to see if the content then shows up. (Ie, just like the plain HTML-file, no PHP whatsoever, just renamed from `.html` to `.php`). If that works, there's something wrong in your other files. – junkfoodjunkie Nov 27 '16 at 02:25
  • @AdamMcGurk A blank page usually means you have an error inside your PHP code. In this case probably `header.php`. Open that file and add this line after ` – icecub Nov 27 '16 at 02:25
  • white screen of death: error checking\display are off, turn them on to see the error. at the top of your php page add: `ini_set('display_errors', 'On'); ini_set('html_errors', 0); error_reporting(-1);` –  Nov 27 '16 at 02:26
  • @junkfoodjunkie So I got rid of my and my index page comes up. I'm downloading xampp so that I can view php files locally and expedite this whole process, so I don't have to "test" on my live website. – Adam McGurk Nov 27 '16 at 02:31
  • The reason it breaks is that you have an opening ` – junkfoodjunkie Nov 27 '16 at 02:37
  • @junkfoodjunkie I didn't know that you could include a non-php file, so I think I'm just going to do that. Now is that include or is it just purely include 'header.html'; – Adam McGurk Nov 27 '16 at 02:43
  • No, you always need to wrap php in tags, unless your whole file is written as PHP. So that would be `` – junkfoodjunkie Nov 27 '16 at 03:03
  • @junkfoodjunkie For some reason, my header still isn't showing up. If we need to take this to chat because it is out of scope of the question that would be awesome! – Adam McGurk Nov 27 '16 at 03:10
  • @AdamMcGurk Each time you get a blank page, you should also look at the "source code" in your web browser. This will show you if there is any code actually there or not. – kojow7 Nov 27 '16 at 05:06
  • Do four things to fix this: 1) Rename index.html to index.php, 2) rename header.php to header.html 3) Change your include line to read the .html file: 4) Remove the tags from your header.html file. – kojow7 Nov 27 '16 at 05:10

0 Answers0