the short answer to this question is, you can’t.
The bottom line is that browsers need to see the unencrypted, plain text source code to create a webpage. For that reason, it’s impossible to hide your HTML source code. If the browser can read it, which it needs to be able to do to render a webpage, then so can a user.
The point is: you don′t WANT to protect web pages. If you have something to protect it doesn′t belong in the web. There is no benefit from hiding code. Don′t mix that up with web security
However, you can make it impossible to read. BASE64 can be parsed by the browser as normal HTML. You can put head and footer html in a mysql db table, each line is a separate row. prefix a random string on to the end of each row as it’s parsed in a simple foreach php loop. The BASE64 decodes it in the PHP and renders it on the page.