1

I've found lots of iterations of this question. Most solutions are something like, "take the header that should be on all pages and turn it into an html file, like this:

(One example that I've tried to put in a file called header.php)

<!--PAGE HEADER-->
<div width="100%">
    <img src="images/headerimage.jpg" height="240">
</div>

"Then make that header.php. Then insert the file into each page in the site like this" -

<?php include 'header.php';?>

I have tried and tried many different combinations of file paths, existing php code that I know works, examples off of the internet. It doesn't work. When I view the source code, i just see:

<?php include 'header.php';?>

It shows up red (Firefox inspector). As far as I understand it, I should see the imported page header code in its place. The code hasn't been imported. And none of the code from header.php gets run.

It looks so easy, I have followed tutorials on Youtube, for them it works, for me, nothing. I have tried setting up Apache server and running it (not really knowing what I was doing though).

CWalk
  • 11
  • 1
  • 2
    are you including the header in a .php file or a .html file? – wheelmaker Sep 15 '18 at 23:18
  • Which tutorials did you follow? It seems like didn't get php working with apache. In general you would use either mod_php (simpler to setup, but a bit slower for complex applications, which you don't seem to have) or php-fpm (a bit faster setup with a php server, and slightly more difficult to setup.) – Arend Sep 15 '18 at 23:19
  • Try the solutions mentioned here https://stackoverflow.com/questions/12142172/apache-shows-php-code-instead-of-executing – mallik1055 Sep 15 '18 at 23:21
  • 1
    Actually, @mattQuest 's question seems to be on point. You can't include a php file from an html file. You'll need to include php from a php file. (e.g. rename your .html file to a .php file). – Arend Sep 15 '18 at 23:21

2 Answers2

0

welcome to StackOverflow!

You can't run PHP in an HTML document. Try to change the file extension from .html to .php

Hope this helps!

2accbot
  • 39
  • 9
  • So are you saying that BOTH files need to be .php? The index.html file AND the header file? I tried changing index.html to index.php, but I can't run it. I am using Dreamweaver as my development environment, even though I don't use any of its features. I was under the impression that if I used the include command, I could insert a php file into an html file. – CWalk Sep 19 '18 at 23:15
0

Dang! I just dug the reply notifications out of my junk mail. Sorry!

Yes, I think my understanding was that I could just copy all the header code out of my html files and paste it into an empty document and call it header.php. Then I would insert the php include statement in my code, and that should basically look like it did before to the browser. But what it looks like is just the php include statement, and no code is imported.

To answer the question what tutorials I followed, I followed a billion tutorials, and all of it is starting to meld into my confused brain. I've actually been trying to do this for years on and off and have never figured it out.

I tried the link recommended above, and got hung up when I didn't have a directory called mods-enabled in my apache2 directory. I have almost no understanding of what is going on behind the scenes, so when I run into something that doesn't fit the example, I just get lost.

And though a couple of days ago I went through this procedure to run apache and then check if php was working, it looked like apache was working and so was php, but even the mail send php file doesn't work when testing locally, so I think php not being enabled is probably the issue. I just have found it very difficult knowing exactly what that means.

CWalk
  • 11
  • 1
  • Still no luck on this whatsoever. I have even tried to comment on this thread unsuccessfully a couple of times (comment didn't go through?). Any ideas on this problem? I feel like it should be easy, and that most websites must do something similar to what I'm asking. – CWalk Oct 05 '18 at 15:26