Question:
How can I put a single php header in all html pages?
Rafeel A
2008-03-04 20:41:41 UTC
I have many html pages in a website. I want to put a single php header in all html pages. How is it possible please step by step.
Four answers:
tigerc10
2008-03-04 20:45:57 UTC
Not possible.



You would be able to put another HTML header in all HTML pages if you set all of the HTML pages to use a single CSS file which contains the header data.
cowgod14
2008-03-04 21:04:37 UTC
This IS possible.



Well, it is possible if you put the PHP header into PHP pages. HTML pages can't contain PHP.



Create one PHP file containing the header. It would be something like:




echo "a bunch of stuff for my header";

?>



Upload this file onto your server as /include/header.php or something.



Then include this in all your PHP pages:




require_once getenv("DOCUMENT_ROOT")."/include/header.php";



//the rest of the page follows

?>



You could use "include" instead of "require_once". They both include other PHP files. I use "require_once" because including the same file twice with "include" will cause a bug. It's basically just a stupid syntax issue.



I do this on my website, though I use functions in my header.php to output different headers and various other things.



Go to http://orbitalcows.com/ . That banner at the top of most pages is created by the header file. I also set the background and text colors that way instead of using CSS.
Kamren Z
2008-03-06 08:56:33 UTC
The first thing you need to do is create you header file. Let's call it "header.inc"



Inside this file write whatever HTML/CSS/JavaScript you want. You can even include PHP inside this file. Just make the extension ".inc"



Next you include the "header.inc" file on any and all pages you want displaying that header via:







This is saying you want to include the "header.inc" file and that it is in the root directory (i.e. the directory you want to store your ".inc" include files)



...



Interested in more PHP / HTML help?

Why not take a class with us @ DevelopIntelligence

http://developintelligence.com/catalog/php-training.php



Hope this helps,

Kamren

Software Technologist @ DevelopIntelligence

http://developintelligence.com
?
2016-12-16 00:15:07 UTC
contain (the two Hypertext Preprocessor or shtml) is a server function. The code is roofed merely while the browser downloads the document from the server. you will no longer see then on your editor or as a preview on your computing device.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...