Michelle Ashwini Michelle Ashwini - 6 months ago 11
CSS Question

Creating a footer file using php

I'm trying to create a php file with my footer details. I want to include this into the necessary pages. The following is my footer.php

footer.php

<?php
echo "<footer class="footer">
<div class="container">
<p class="text-muted"><a href="contactus.html">Contact Us</a></p>
<p class="text-muted"> Copyright &copy; <span id="yearfooter"> </span>. All rights reserved.</p>
</div>
</footer>";
?>


This is the line I include into my html file to include this footer.php

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


But when uploaded to my website, it is not showing the footer file. This is the very first time I'm trying out PHP. I'm not sure if there is something else I'm supposed to do or where I'm going wrong. Any help is much appreciated!

UPDATE

I still cant get this to work. I've also added a .htaccess file and it still doesnt help.

.htaccess

AddType application/x-httpd-php .html


Update

I've managed to get this working. There was some config issues in the server side. Thanks!

Answer

Try wrapping your echo in single quotes:

<?php
    echo '<footer class="footer">
              <div class="container">
                  <p class="text-muted"><a href="contactus.html">Contact Us</a></p>
                  <p class="text-muted"> Copyright &copy;     <span id="yearfooter"> </span>. All rights reserved.     </p>
</div>
          </footer>';
?>

And no space between ? and php

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