Your approach is generally correct, but the issue you're encountering is likely due to the order in which you're including the content within masterPage.php. Right now, you're including the content before both the header and footer.
To fix this, you should include the content between the header...