I have a header that will be on every page of my site and instead of adding the html
/php
to each page I was thinking I could just make a template file and include it with a php include()
so it's easier to modify if I have to change something. Is there a better way to do this and would using the PHP
include slow down my site? Thanks in advance.
Asked
Active
Viewed 635 times
4

imsheth
- 31
- 2
- 18
- 36

Joe Scotto
- 10,936
- 14
- 66
- 136
-
2is this a bare-bones PHP or are you using a framework of sorts? What you have described is exactly what PHP `include` and `require` are for. – B-and-P Oct 13 '15 at 07:22
-
Barebone php. Would using `include` / `require` slow down my performance in any way? – Joe Scotto Oct 13 '15 at 07:23
-
Including headers, footers and other static contents on all pages that will have the same content is generally a good idea, it's easier to maintain and update. You might want to take a look at [this StackOverflow](http://stackoverflow.com/a/2418514/4535200). – Qirel Oct 13 '15 at 07:24
-
@JoeScotto Depends how many files are you including, your other option is Server Side Includes (on Apache), other servers may have their own implementation. See this SO question: http://stackoverflow.com/questions/2993858/ssi-or-php-include – B-and-P Oct 13 '15 at 07:26
1 Answers
1
you can use include/require() but please reamember that same file doesn't include twice otherwise it will conflict.You can declare variable globaly so that it provide you easy way.

Chirag Senjaliya
- 460
- 3
- 16