The best option is probably to (re) write the header and footer using python.
If the headers and footers are relatively static, you can also generate them once with php (or once every x minutes) and include them from the file system. (You probably already thought about it and rejected this idea because your sites are too dynamic to use this option?)
Although I would not recommend it, you can also use some form of AJAX to load parts of the page, and nothing prevents you from loading this content from a php based system. This can lead to all parts being dynamic. Your pages will probably look ugly on loading, and now you will create more requests on the server than you need, but if it is a large site, it can be large.
Warning. If you have user logins on both systems, you are likely to run into problems when people can only log in to half of your site.
source share