skip to Main Content

I want a php file to be included to display a footer of my web pages. I’m using godaddy shared hosting with php7.4.
I created a footer.php file like thus:

<?php
    echo "<p>Copyright &copy; 1999-" . date("Y") . " W3Schools.com</p>";
?>

A html file "test.html" to display the footer is like thus:

<html>
<body>
    <h1>Welcome to my home page!</h1>
    <p>Some text.</p>
    <p>Some more text.</p>
    <?php include 'footer.php';?>
</body>
</html>

The result displays the test.html file without the footer file display.
Thanks in advance for any positive solutions.
Cheers,
Dave

As stated above, it didn’t display the footer file verbiage.

2

Answers


  1. Modify you code as below in html files

      <html>
       <body>
        <h1>Welcome to my home page!</h1>
        <p>Some text.</p>
        <p>Some more text.</p>
        <p>Copyright &copy; 1999- <script>document.write(/d{4}/.exec(Date())[0])</script>  W3Schools.com</p>
       </body>
     </html>
    

    Make Bulk file replace in any notepad ++ like editor with

    replace in file

    Your php include file line

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

    with

      <p>Copyright &copy; 1999- <script>document.write(/d{4}/.exec(Date())[0])</script>  W3Schools.com</p> 
    

    Other method is to make apache interpret html files as php

    <IfModule mod_php5.c>
    <Directory /var/www/vhosts/example.com/httpdocs>
    AddHandler php5-script .php .html .htm
    AddType text/html .php .html .htm
    </Directory>
    </IfModule>
    

    refer to this link

    https://www.plesk.com/kb/support/how-to-configure-apache-to-process-php-code-inside-an-html-file-on-a-plesk-server/

    This is not just for plesk server but can be used for any apache based server if you have access to these files.

    Login or Signup to reply.
  2. For your informaton, HTML file cannot render PHP commands under normal circumstances.

    However, you may use a small trick to do the job

    Assuming that your footer is a php (footer.php)

    <?php
        echo "<p>Copyright &copy; 1999-" . date("Y") . " xxxx.com</p>";
    ?>
    

    Then you may use

    1. a DIV to display the footer
    2. Use jquery load to put the footer contents there

    So the code will be:

    
    <script
      src="https://code.jquery.com/jquery-3.7.1.js"
      integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4="
      crossorigin="anonymous"></script>
    
    
    <div id="footerplace" style="width:100%;text-align:center;"></div>
    
    
    <script>
    $("#footerplace").load("footer.php");
    </script>
    
    

    So the following will be a sample:

    
    
    Test <br>
    Test2 <br>
    Test3 <br>
    Test4 <br>
    Test5 <br>
    
    
    
    <script
      src="https://code.jquery.com/jquery-3.7.1.js"
      integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4="
      crossorigin="anonymous"></script>
    
    
    <div id="footerplace" style="width:100%;text-align:center;"></div>
    
    
    <script>
    $("#footerplace").load("footer.php");
    </script>
    
    

    The result will be like:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search