Reputation: 3356
I have been trying to search a solution online and on stackoverflow but did not come across any satisfactory solution.
I wanted to know how can i include (if required) header.php
and footer.php
automatically in the new PHP pages that i create, at present whenever i create a new PHP file i manually add header.php
on top and footer.php
at the bottom, I dont really have a problem with doing this but i was wondering if this is how everyone does it and if not what is the best solution to this.
I know I could takeup any framework out there and use that because may be they include the header and footer automatically, but i am referring to custom PHP coding.
I will really appreciate views of experienced developers out there.
Upvotes: 0
Views: 267
Reputation: 943108
The usual approach is to use the front controller design pattern.
Use a single PHP file to load all the pages. Have it include the header and footer and use the URL (and whatever other information you like) to determine which content to include.
PHP developers often use mod_rewrite
to map URLs onto a single script. You could also use the Apache alias
directive.
Upvotes: 2