Reputation: 3812
I have an extraordinarily simple website:
index.html contains:
<html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>
</body>
</html>
It is in /usr/share/nginx/html
footer.php is in the same directory and is:
<?php
echo "<p>printed!!</p>";
?>
When I go to http://MY_IP_address/footer.php I get the proper output of just a blank page with "printed!!" at the top left.
When I go to http://MY_IP_address/ I get: " Welcome to my home page!
Some text.
Some more text. "
But I do not get "printed!!" written anywhere.
I am assuming that somewhere I missed something in my config files, but I can't figure out what it is.
Upvotes: 1
Views: 347
Reputation: 6896
The file which contained include()
is a file with .html
extension, thus it's not interpreted by Apache. Thus, the code in index.html
was not included. (Credits to @RiggsFolly for the improved explanation)
Unless your server is set to parse .html
files as PHP, it will not be included.
Thus you'll need to rename it to index.php
.
The
include()
function in PHP includes code from other PHP files and copies them into the file that uses the include statement.
Source:
Upvotes: 3
Reputation: 642
Php tags(<?php ?>
) can only be parsed when file extension is php.
So,
Change file name from index.html
to index.php
Upvotes: 1