Server Side Includes putting php in html

4.1k views Asked by At

I am trying to print the output of php file in HTML using server side includes. Here is the code of index.html file.

<!DOCTYPE html> 
<html>
  <body>
    <!--#include file="include.php" -->
    <h1>This is a Example Of Server Side Includes</h1>
  </body>
</html>

Here is the code of my include.php file.

<?php
  echo "Hello From PHP\n";
  echo "Hello To HTML\n";
?>

Here is the content of my .htaccess file.

Options +Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

All the files located in /var/www/html.

This is the screen shot of while executing index.html.

enter image description here

Does Server Side Includes also work in localhost? if yes How to configure? And where to put .htaccess file in var/www/html.

3

There are 3 answers

4
tdoggy On

If you're using PHP, you need to have a file with the PHP extension. You cannot use PHP in a file with an HTML extension. Change index.html to index.php

0
eap314 On

If localhost does support ssi, it wouldn't be supported in an html file. Try changing the name to index.shtml. Also, since your include path is relative, try <!--#include file='...'-->

Or, you could just try what the other answers say, and use php instead.

0
Salem On

If you are using Nginx, an example of how to use SSI (Server Side Includes) is below:

<!--# include virtual="/body.php?argument=value" -->

Nginx SSI Docs