Custom php code using the site header and footer
Yes, you'll generally solve this by writing a custom module. In your .module file you'll probably want, as a minimum:


An implementation of hook_permission to provide access control to your content
An implementation of hook_menu to define the routing to your page, in other words which URLs will cause your custom code to be invoked.
The actual callback which generates the content.


In the callback you can use whatever PHP code you want, though if you do use Drupal's APIs and established good practice you'll be less likely to create security weaknesses and your code will work better with other modules. That's likely to save you time in the long run.