In `header.php` I used variables for the title, description, etc. and then in each page I specified the values for those variables. This way each page had the same header HTML code, but with a different title, description and so on.
I do my PHP in completely different way, which in turn was the way I did ASP back in the day, also in a weird way.
All my HTML is held in template .html files, with %%PLACEHOLDER%% text where the dynamic content should be, Then my index.php is the main 'app' loading in the templates to build the output, doing string replaces on the html, and then a single final 'echo' to send the result to the user at the end of the process.
I think this is called 'code behind' - I've just always had a problem with mixing code and layout in the same file.
Yes, I've done it that way before. Actually just did a few weeks ago when building a frontend for a WordPress site. The frontend consumes the API and takes care of lightning-fast delivery by cutting out all the normal WordPress stuff that normally runs, when building a theme.
The structure was something like this:
In `header.php` I used variables for the title, description, etc. and then in each page I specified the values for those variables. This way each page had the same header HTML code, but with a different title, description and so on.