This question already has an answer here:
I'm trying to include some PHP script in with a HTML file, while I have found the command that achieves this, there seems to be an error in the way that I've layed out my code. I feel like I've missed a parentheses or something.
Here is a section of my HTML:
<title>Web Workers :: Home</title>
</head>
<body>
<?php
echo "<h1>Test</h1>";
include_once("htmlstatic.php");
?>
<nav id="navlist">
<ul>
<li class="links"> <a href="index.html">Home</a> </li>
<li class="links"> <a href="topic1.html">Web Workers</a> </li>
<li class="links"> <a href="register.html">Register</a> </li>
<li class="links"> <a href="quiz.html">Quiz</a> </li>
<li class="links"> <a href="results.html">Results</a> </li>
<li class="links"> <a href="about.html">About</a> </li>
<li class="links"> <a href="enhancements.html">Enhancements</a> </li>
</ul>
</nav>
<hr class="whitehr"/>
</body>
</html>
And here is my PHP:
<?php
echo "<h1>Web Workers</h1>";
echo "<hr class='whitehr'/>";
echo "<p>test</p>";
?>
Here is the output
</div>
Your file has .html
extension that's why server cannot interpret the code starts with <?php
either tell server to interpret .html
as .php
or use .php
file extension
for method first try below in .htaccess
file
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
You cannot include a .php
file in .html
file, nor can you execute a php
code in a .html
file, rename your .html
to .php
to execute the php
code. For your php code to be interpreted your files must have .php extension.
Edited:
As you did not mention in the question i am assuming that you are using the default php installation, with no setting to include PHP files in an HTML file.