Search code examples
phphtmlcssfooter

How to include php page which include also a css file?


I have searched a lot over stackoverflow and found related answer but those were not perfect solution of this problem. I have a directory named root. Inside the root folder there are 1 folder named footer and 1 file named index.php There are 2 files named footer.php and footer.css in the footer directory. I want to include footer.php file from index.php page. footer.php page has a stylesheet link with footer.css page. But index.php page can not find footer.css page.

Please see code from Pastebin.

footer.php

index.php


Solution

  • This will produce horrible html code ... footer.php is a full html page - it has Doctype, html tag, body tag etc. The same goes with index.php. Including footer.php in index.php will produce invalid html file, with html tag inside another html tag (html > body > html > body) ...

    The reason why You can't see footer.css it's because it's placed in footer directory. So while you request index.php the proper path to css should be footer/footer.css, and You're getting just footer.css (because path for footer.php is relative).