Keep the code in a separate file, say common.php
or lib/myfile.php
Then, just require()
it:
require("common.php");
Or you can look at the fancy class loading provided by Packagist but for the most compatability or simplicity the above method will work