I have the header.php which has the basic logic applying to all php files inside web root folder.
Let's suppose I have the following 5 pages "index.php, post.php, list.page, read.page, update.page" in the folder.
Index.php begins with <?php include "header.php" ?> .
post.php begins with <?php include "header.php" ?> .
list.php begins with <?php include "header.php" ?> .
read.php begins with <?php include "header.php" ?> .
update.php begins with <?php include "header.php" ?> .
All php files in the folder begins with <?php include "header.php" ?> .
I doubt why I should put the code "<?php include "header.php" ?>" in all php files in the folder.
I'll be happy if all php files in the folder has the code of header.php automatically without the code <?php include "header.php" ?>.
coldFusion has this kind of function.
The file of the name is "application.cfm"
When a user open any coldFusion(cfm) files in a folder,
coldFusion server searchs application.cfm in the folder before it reads the requested cfm files.
If application.cfm is in the folder, it reads application.cfm first and reads the requested cfm file.
If application.cfm is not in the folder, it reads the requested cfm file.
If a user calls application.cfm directly, it causes error.
Application.cfm is not a url file.
Application.cfm is included in the top of any cfm files without include code.
coldFusion developers usually put logic rather than display in the file of application.cfm
In my experience, it is very useful.
How about PHP?
So then swap the logic the other way around?
Instead of having each file include the header... that's how people build frameworks
You could look at the auto_prepend_file ini setting for PHP, but that'll apply automatically prepend the file to all php files in your website (not just in the root).
What about having an index.php which includes header.php and then includes the appropriate page file (post.php, list.php etc)?
Yeah, that was a nice feature of CF. But you are using PHP now. The change is a nuisance if you are a serious CF developer, but that's what learning a new scripting language entails. Wait until you hit PHP's approach to database access - it'll drive a CF developer like you completely nuts.
You may want to consider using a CMS (WordPress, Joomla, Drupal, Barebones CMS, etc.) or a framework (Zend, CakePHP, etc).