Yes, but it's not recommended.
Remove the start and end tags (the first
<?php and last
?>) from the files you want to include and rename them to a .txt extension.
So (hypothetically) mainpage.php:
...becomes mainpage.txt:
Then, to access the file so it parses correctly, use this code:
The included file should
not have a .php extension since the script is simply grabbing the contents of the file and evaluating it as PHP code. If you name it .php, any internal PHP tags could be parsed by the server it's residing on before being sent to the requesting server.
Any file included should be written as a typical PHP file, except you
must omit only the start and end PHP tags, and not give it a .php entension.
The reason this is not recommended is because the file must be public to be seen by external servers, and the code is readable because it must be readable by the requesting servers. Because of this, anyone can access and read your code. So try to obfuscate it with really long and weird directory/file names.
Also, if the host server goes down, all external sites using the hosted files cease to function as well.